Looking for Dynamic Control Solution

M

MikeY

Hi Everyone,

I am working in C#, windows forms.My question is this. All my button dynamic
controls properties are present and accounted for except for the"FlatStyle"
properties. I can't seem to figure out, if there is a way of using
polymorphic way (if that is a word) of doing this particular property. A
sample of my code is as follows:

DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new
Size(95, 20), "Name",1,""); << Calling

this.btnSearchByName.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
<<<Had to manually input this property here

public static void ButtonControl(Control parent, Control aControl, Point
Location, Size Size, String strText, int TabIndex, string strName)
{
aControl.Location = Location;
aControl.Size = Size;
aControl.TabIndex = TabIndex;
aControl.Text = strText;
aControl.Name = strName;
aControl.Cursor = System.Windows.Forms.Cursors.Hand;
aControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
aControl.TabStop = true;
aControl.Enabled = true;
parent.Controls.Add(aControl);
}

What I would like to do is to add this property with in my ButtonControl
function instead of manually adding this below each & every call. Is there a
way of doing this. Also the FlatStyle does not appear in the Intellisense
after "aControl." If there is a way, perhaps someone could provide a quick
simple sample.

Thank you all in advance and have a good weekend.

MikeY
 
G

gcl

cast it.. For example,

((System.Windows.Forms.Button) (aControl)).FlatStyle =
System.Windows.Forms.FlatStyle.Flat;

Now I got a question for you..
How are you going to wire the events for these dynamic
controls?

Thanks..
 
M

MikeY

Hi GCL

I've wired the event with my first line, control:

DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new
Size(95, 20), "Name",1,"");

This control/object is being call in/from my frmMain and calls the function
"ButtonControl" with in a seperate .cs called "Dynamic Controls.cs" my
control does all the work of position (5,75), size(95,20) etc. Thank you for
your solution. But, (there always is, lol) your solution is presently what I
am already using, re: (my second line):

this.btnSearchByName.FlatStyle = System.Windows.Forms.FlatStyle.Popup;

This way is working perfectly, but I was looking for more of a polymorphic
way of doing this instead of everytime that I'm writing an control/event I
have to write a "FlatStyle" property after it. I was looking for a way of
adding this to my function "ButtonControl" just like "aControl.Font", but I
can't seem to find the solution myself. hmmm It seems like I'm always coming
up with these querky questions while trying to learn C#, lol. Anyhow, thank
you again GCL. I'll still look for the solution and I'm sure it is one of
those simple things that I've just overlooked.

MikeY
 
G

gcl

Well,

in that function you can check what type of control is
that and check if the control have the FlatStyle
property and if it does, then your
can cast it to button control and set its property

From your message, I still don't see where u wired
to control's events. I was talking about, like for
example,
500 buttons controls, and when the user click
on one of the control, it will trigger the delegate

Anyway, I done them in different way..

Thanks.
 
M

MikeY

Aaaaaaaaah, I've misunderstood you, sorry bro.

I wire the event like this:
btnSearchByName.Click += new System.EventHandler(SearchBoxArea);

You can just treat the "btnSearchByName" just like anyother button, Label,
TextBox, Gridbox etc ie txtBoxFName.text
I do enjoy using Dynamic controls, but sometimes like this & especially
being that I'm still learning the ropes, it can be head scratching, lol.
Anyhow have a great weekend.

Hey if you want a small samply on how I approach this please drop me a line.

MikeY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top