471,092 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Looking for Dynamic Control Solution

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
Nov 13 '05 #1
3 6634
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

"gcl" <ln*******@comcast.net> wrote in message
news:0a****************************@phx.gbl...
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..

-----Original Message-----
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,btnSearchByNam e, 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
.

Nov 15 '05 #2
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.

-----Original Message-----
Hi GCL

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

DynamicControls.ButtonControl(this,btnSearchByNam e, new Point(5, 75), newSize(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" mycontrol does all the work of position (5,75), size (95,20) etc. Thank you foryour solution. But, (there always is, lol) your solution is presently what Iam 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 polymorphicway of doing this instead of everytime that I'm writing an control/event Ihave to write a "FlatStyle" property after it. I was looking for a way ofadding this to my function "ButtonControl" just like "aControl.Font", but Ican't seem to find the solution myself. hmmm It seems like I'm always comingup with these querky questions while trying to learn C#, lol. Anyhow, thankyou again GCL. I'll still look for the solution and I'm sure it is one ofthose simple things that I've just overlooked.

MikeY

"gcl" <ln*******@comcast.net> wrote in message
news:0a****************************@phx.gbl...
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..

>-----Original Message-----
>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,btnSearchByNam e,
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
>
>
>.
>

.

Nov 15 '05 #3
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

"gcl" <ln*******@comcast.net> wrote in message
news:04****************************@phx.gbl...
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.

-----Original Message-----
Hi GCL

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

DynamicControls.ButtonControl(this,btnSearchByNam e, 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

"gcl" <ln*******@comcast.net> wrote in message
news:0a****************************@phx.gbl...
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..


>-----Original Message-----
>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,btnSearchByNam e, 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
>
>
>.
>

.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by charliewest | last post: by
3 posts views Thread by Assaf | last post: by
4 posts views Thread by brett | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.