Solved

Does not contain definition for BorderStyle - UH!?

Posted on 2008-10-14
5
610 Views
Last Modified: 2012-06-22
Experts,

I have the following control declared:

                        controlPanel[i] = new System.Windows.Forms.Panel();
                        this.Controls.Add(controlPanel[i]);
                        controlPanel[i].Name = "Panel" + i.ToString();
                        controlPanel[i].BackColor = System.Drawing.Color.Gray;
                        controlPanel[i].Location = new System.Drawing.Point(x, y);
                        controlPanel[i].Size = new System.Drawing.Size(200, 80);
                        controlPanel[i].TabIndex = 1;
                        controlPanel[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                        controlPanel[i].Parent = panel1;


When compiling, it errors on the line:

controlPanel[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

Does not contain definition for BorderStyle, and I can see that intellisense doesnt give me anything for borderstyle, but all other properties are available.

Please help!
0
Comment
Question by:mhouldridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 22711868
need more code, and exactly what you have -- i just ran this without the location and parent and it compiled fine.
0
 

Author Comment

by:mhouldridge
ID: 22711960
The error points to the BorderStyle line, with:

.Windows.Forms.Control' does not contain a definition for 'BorderStyle' and no extension method 'BorderStyle' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?)      C:\MonitorServer\Monitor Server\Monitor Server\Form1.cs      92      41      Monitor Server
0
 
LVL 22

Expert Comment

by:p_davis
ID: 22712039
so you have an array of controls?

Control doesn't have BorderStyle but panel does. you will either have to cast it if the type of control is panel

controlPanel[i].GetType() == typeof(Panel)

or make the array an array/list of panels
0
 

Author Comment

by:mhouldridge
ID: 22712076
Ah, that's sorted it.

Im new to Windows forms, and I wasn't aware that you could create an array of Panels, and I thought Control was a generic to create arrays of all windows controls, apologies!

Just one more quick question.  I've set the label.Parent value to the panel, and the labels x, y co-ordinate to panel.Left + 10, panel.Top + 10, but this doesnt work either.

Any suggestions?

 
0
 
LVL 22

Accepted Solution

by:
p_davis earned 500 total points
ID: 22712123
you can do that with control but would just have to cast if you are going to be using more than one type of control in that method/event. if not, i would just use the array of panels.

what is it doing and what are you expecting it to do with the location?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question