Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / November 2005

Tip: Looking for answers? Try searching our database.

Position label and text in CreateComponentsCore()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gabriel Lozano-Morán - 02 Nov 2005 16:54 GMT
Hey I hope someone can help me with a clean solution for the following
puzzle:

I have written a custom toolboxitem that overrides the
CreateComponentsCore() operation that returns two objects, a subclassed
label and a subclassed textbox. The purpose is to create a label and a
textbox that represent a database field (something similar to Microsoft
Access when dragging and dropping a field on a form).

Now my problem is how to position the two controls? In the
CreateComponentsCore() you cannot get the location on the designer since
they are not yet dropped on the designer yet. This means that both controls
will be created at the exact same location thus overlapping eachother. Is
there a clean way to position both controls in the CreateComponentsCore() so
that the textbox control will be positioned behind the label control?

I was thinking of adding a property named ShiftLeft to the subclassed
TextBox, set the value of ShiftLeft in the CreateComponentsCore() and in the
constructor of the subclassed Textbox make sure that TextBox.Left =
TextBox.Left + ShiftLeft but there has to be a better way (?)

Also I do NOT want to create a user control consisting of my custom label
and custom textbox  because after creating the user should be able to move
label and textbox around as two seperate components.

Many thanks for any leads :)

Gabriel Lozano-Morán
Real Software
Gabriel Lozano-Morán - 03 Nov 2005 09:48 GMT
I believe that I have found a possible solution for my problem I hope it
might help someone:

...
private delegate void SetRelativeMethodHandler(Control label, Control
control);
...

protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
   Control control = (Control) host.CreateComponent(...);
   Control label = (Control) host.CreateComponent(..);

   Control c = host.RootComponent as Control;

   ...
   c.BeginInvoke(new SetRelativeMethodHandler(OnSetRelativePosition), new
object[] {label, control});
   ...

   return new IComponent[] {control, label};
}

private void OnSetRelativePosition(Control label, Control control)
{
   // When this is invoked we have the location of both controls
   ...
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.