简体   繁体   中英

Composite Winform Control in C#

Composite Control

Image http://www.freeimagehosting.net/uploads/a51136603b.png

Howdy,

I am hoping for some help. I wanted to create a Composite Control, shown in the screenshot above. As seen in the screen shot, the Parent Control is Label 1; it contains child controls Label2, Label3, and Label4, and a PictureBox containing a pre-defined image.

I would like to turn the above into a composite control, in C#, with the following specifications :

The Parent Label, Label1, should generate a Click Event. Child controls Label2, Label3, and Label4 are to be assigned ToolTips on MouseMove Event, while the last Child Control, PictureBox, should have both ToolTips on MouseMove Event and Click Event.

Likewise, the locations of Label2, Label3, Label4, and PictureBox within the Parent Label1 control must be set as properties, as are their texts and sizes.

How do I go about incorporating all these into one composite control named AilmentLabel ? Any advise or information is greatly appreciated. Thank you so much.

MSDN provides a very thorough walkthrough of how to do this. You should read the walkthrough: "Authoring a Composite Control with C#"

It sounds like you want to create a 'UserControl'. It's just like any other control but you can add controls to the surface. Then you would expose properties in the UserControl source that would propagate the changes thru to the appropriate control:

public string Label1Text {
    get { return this.Label1.Text; }
    set { this.Label1.Text = value; }
}
...etc...

You can even expose Click events in this manner, and allow users to subscribe to them. Then you can drag/drop this new control onto your other window surfaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM