[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Does not contain definition for BorderStyle - UH!?

Posted on 2008-10-14
5
Medium Priority
?
622 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 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