|
Prev: Bug in CAB-File Wizard?
Next: Recording Audio using WaveIn API and Receiving SMS Message Results In Application Crash
From: Mark Wilhelm on 10 Apr 2008 23:31 I'm creating some buttons in a loop and adding them to a panel's Controls collection. I'm setting various properties, one being Visible (true). The issue is, is that I only see one button and when I look at the buttons in the Watch window the visible property is set to false. What am I doing wrong and/or not understanding? ... System.Windows.Forms.Button censusButton = new Button(); censusButton.Name = "censusButton" + i.ToString() + j.ToString(); censusButton.Text = "New Button"; censusButton.BringToFront(); censusButton.Enabled = true; censusButton.Visible = true; this.panelPatient.Controls.Add(censusButton); ... Windows Mobile 6 Pro C#
From: Christopher Fairbairn on 11 Apr 2008 00:22 Hi, "Mark Wilhelm" <MarkWilhelm(a)discussions.microsoft.com> wrote in message news:61FF799E-AAE4-477A-ACB6-912AD4D05792(a)microsoft.com... > I'm creating some buttons in a loop and adding them to a panel's Controls > collection. I'm setting various properties, one being Visible (true). > The > issue is, is that I only see one button and when I look at the buttons in > the > Watch window the visible property is set to false. What am I doing wrong > and/or not understanding? In your code sample I do not see you setting the size or location of your controls this will mean they will take on their default values which will cause each control to neatly cover the ones previously inserted. Try adding the following lines into your loop: // Position this control explictly at the required (x,y) co-ordinate // and make it 100x20 pixels in size censusButton.Location = new Point(10, i * 22); censusButton.Size = new Size(100, 20); If you don't want to manually position each of the controls you would need to investigate placing them within a panel or other container and using docking to position them. For example, to add the controls one after another at the top of the form add the following line instead of the two mentioned above. censusButton.Dock = DockStyle.Top; Don't worry about Visible being false even though you set it explictly to true. This is probably because the form is not truely visible yet. If you put a break point in a button press event handler etc (or anything else that occurs after the form is made visible) you should see that the Visible property returns correct results. Hope this helps, Christopher Fairbairn
From: Mark Wilhelm on 11 Apr 2008 15:55 Christopher, Thanks for the insight. Some of the code I didn't show was the location and size. However, I must have not been giving enough offset, because I was always seeing the last button. I changed some of the location math and was able to see more buttons. So I'm good to go. Now, any quick pointers on getting click events made for these dynamic buttons? Again, thanks. Mark "Christopher Fairbairn" wrote: > Hi, > > "Mark Wilhelm" <MarkWilhelm(a)discussions.microsoft.com> wrote in message > news:61FF799E-AAE4-477A-ACB6-912AD4D05792(a)microsoft.com... > > I'm creating some buttons in a loop and adding them to a panel's Controls > > collection. I'm setting various properties, one being Visible (true). > > The > > issue is, is that I only see one button and when I look at the buttons in > > the > > Watch window the visible property is set to false. What am I doing wrong > > and/or not understanding? > > In your code sample I do not see you setting the size or location of your > controls this will mean they will take on their default values which will > cause each control to neatly cover the ones previously inserted. Try adding > the following lines into your loop: > > // Position this control explictly at the required (x,y) co-ordinate > // and make it 100x20 pixels in size > censusButton.Location = new Point(10, i * 22); > censusButton.Size = new Size(100, 20); > > If you don't want to manually position each of the controls you would need > to investigate placing them within a panel or other container and using > docking to position them. For example, to add the controls one after another > at the top of the form add the following line instead of the two mentioned > above. > > censusButton.Dock = DockStyle.Top; > > Don't worry about Visible being false even though you set it explictly to > true. This is probably because the form is not truely visible yet. If you > put a break point in a button press event handler etc (or anything else that > occurs after the form is made visible) you should see that the Visible > property returns correct results. > > Hope this helps, > Christopher Fairbairn > > >
From: Chris Tacke, eMVP on 11 Apr 2008 16:08
censusButton.Click += MyOnButtonClickHandler; -- Chris Tacke, Embedded MVP OpenNETCF Consulting Giving back to the embedded community http://community.OpenNETCF.com "Mark Wilhelm" <MarkWilhelm(a)discussions.microsoft.com> wrote in message news:A1E46565-F246-407C-8E85-6573ADC4B630(a)microsoft.com... > Christopher, > > Thanks for the insight. Some of the code I didn't show was the location > and > size. However, I must have not been giving enough offset, because I was > always seeing the last button. I changed some of the location math and > was > able to see more buttons. So I'm good to go. > > Now, any quick pointers on getting click events made for these dynamic > buttons? > > Again, thanks. > > Mark > > "Christopher Fairbairn" wrote: > >> Hi, >> >> "Mark Wilhelm" <MarkWilhelm(a)discussions.microsoft.com> wrote in message >> news:61FF799E-AAE4-477A-ACB6-912AD4D05792(a)microsoft.com... >> > I'm creating some buttons in a loop and adding them to a panel's >> > Controls >> > collection. I'm setting various properties, one being Visible (true). >> > The >> > issue is, is that I only see one button and when I look at the buttons >> > in >> > the >> > Watch window the visible property is set to false. What am I doing >> > wrong >> > and/or not understanding? >> >> In your code sample I do not see you setting the size or location of your >> controls this will mean they will take on their default values which will >> cause each control to neatly cover the ones previously inserted. Try >> adding >> the following lines into your loop: >> >> // Position this control explictly at the required (x,y) co-ordinate >> // and make it 100x20 pixels in size >> censusButton.Location = new Point(10, i * 22); >> censusButton.Size = new Size(100, 20); >> >> If you don't want to manually position each of the controls you would >> need >> to investigate placing them within a panel or other container and using >> docking to position them. For example, to add the controls one after >> another >> at the top of the form add the following line instead of the two >> mentioned >> above. >> >> censusButton.Dock = DockStyle.Top; >> >> Don't worry about Visible being false even though you set it explictly to >> true. This is probably because the form is not truely visible yet. If you >> put a break point in a button press event handler etc (or anything else >> that >> occurs after the form is made visible) you should see that the Visible >> property returns correct results. >> >> Hope this helps, >> Christopher Fairbairn >> >> >> |