c# - Centered ColorDialog -


i need show colordialog docked @ left of form.

i know how positionate localizable object left of form, how change startposition of colordialog?

i think need subclassit famous "centeredmessagebox" classes, don't know how it...

any help?

this poor code:

private sub globalhotkey_ctrl_x_press(byval s object, byval e shortcut.hotkeyeventargs) handles globalhotkey_ctrl_x.press     colordialog1.color = rgb     colordialog1.showdialog() end sub 

maybe better if add property "position" , "startposition" default colordialog control, said don't know how , maybe else have made class before , can post here...

thankyou.

update:

this using mzn solution:

enter image description here

i wrote sample while experimenting achieve objectives.

class x class inherits colordialog , gets it's main window moves created.

the dllimport attribute .net p/invoke mechanism. tell compiler we're calling native function. needs signature, body must remain empty.

the rect structure boiler-plate code pinvoke.net

tell me if of use you, , if have questions. :)

imports system.runtime.interopservices  public class form1     dim cd new x      private sub form1_load(sender object, e eventargs) handles mybase.load         text = handle.tostring()     end sub      private sub form1_mousedoubleclick(sender object, e mouseeventargs) handles mybase.mousedoubleclick         cd.showdialog(me)     end sub      'import' native function user32.dll     <dllimport("user32.dll", setlasterror:=true, charset:=charset.auto)> _     public shared function movewindow(hwnd intptr, x integer, y integer, cx integer, cy integer, _                                                                   rpt boolean) boolean     end function      <dllimport("user32.dll", charset:=charset.auto)> _     private shared function getclientrect(byval hwnd system.intptr, byref lprect rect) integer     end function end class  public class x     inherits colordialog      protected overrides function hookproc(hwnd intptr, msg integer, wparam intptr, lparam intptr) intptr         system.diagnostics.debug.print(hwnd)          'this call messes things, border style         'i don't know how fix now, there should         'be way tell move without changing border style         form1.movewindow(hwnd, 50, 110, 333, 333, true)          return mybase.hookproc(hwnd, msg, wparam, lparam)     end function  end class   'i got class http://www.pinvoke.net/ useful! use is. <structlayout(layoutkind.sequential)> _ public structure rect     private _left integer, _top integer, _right integer, _bottom integer      public sub new(byval rectangle rectangle)         me.new(rectangle.left, rectangle.top, rectangle.right, rectangle.bottom)     end sub     public sub new(byval left integer, byval top integer, byval right integer, _                    byval bottom integer)         _left = left         _top = top         _right = right         _bottom = bottom     end sub      public property x integer                     return _left         end         set(byval value integer)             _right = _right - _left + value             _left = value         end set     end property     public property y integer                     return _top         end         set(byval value integer)             _bottom = _bottom - _top + value             _top = value         end set     end property     public property left integer                     return _left         end         set(byval value integer)             _left = value         end set     end property     public property top integer                     return _top         end         set(byval value integer)             _top = value         end set     end property     public property right integer                     return _right         end         set(byval value integer)             _right = value         end set     end property     public property bottom integer                     return _bottom         end         set(byval value integer)             _bottom = value         end set     end property     public property height() integer                     return _bottom - _top         end         set(byval value integer)             _bottom = value + _top         end set     end property     public property width() integer                     return _right - _left         end         set(byval value integer)             _right = value + _left         end set     end property     public property location() point                     return new point(left, top)         end         set(byval value point)             _right = _right - _left + value.x             _bottom = _bottom - _top + value.y             _left = value.x             _top = value.y         end set     end property     public property size() size                     return new size(width, height)         end         set(byval value size)             _right = value.width + _left             _bottom = value.height + _top         end set     end property      public shared widening operator ctype(byval rectangle rect) rectangle         return new rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height)     end operator     public shared widening operator ctype(byval rectangle rectangle) rect         return new rect(rectangle.left, rectangle.top, rectangle.right, rectangle.bottom)     end operator     public shared operator =(byval rectangle1 rect, byval rectangle2 rect) boolean         return rectangle1.equals(rectangle2)     end operator     public shared operator <>(byval rectangle1 rect, byval rectangle2 rect) boolean         return not rectangle1.equals(rectangle2)     end operator      public overrides function tostring() string         return "{left: " & _left & "; " & "top: " & _top & "; right: " & _right & "; bottom: " & _bottom & "}"     end function      public overloads function equals(byval rectangle rect) boolean         return rectangle.left = _left andalso rectangle.top = _top andalso rectangle.right = _right andalso rectangle.bottom = _bottom     end function     public overloads overrides function equals(byval [object] object) boolean         if typeof [object] rect             return equals(directcast([object], rect))         elseif typeof [object] rectangle             return equals(new rect(directcast([object], rectangle)))         end if          return false     end function end structure 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -