Solved

Does not contain definition for BorderStyle - UH!?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

12 Experts available now in Live!

Get 1:1 Help Now