Solved

Does not contain definition for BorderStyle - UH!?

Posted on 2008-10-14
5
598 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now