Solved

Does not contain definition for BorderStyle - UH!?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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