Click here to Skip to main content
15,898,571 members
Home / Discussions / C#
   

C#

 
GeneralRe: win6x_registry_tweak Pin
Gregan Dark23-Oct-17 2:57
Gregan Dark23-Oct-17 2:57 
GeneralRe: win6x_registry_tweak Pin
Dave Kreskowiak23-Oct-17 4:36
mveDave Kreskowiak23-Oct-17 4:36 
GeneralRe: win6x_registry_tweak Pin
Gregan Dark23-Oct-17 9:23
Gregan Dark23-Oct-17 9:23 
GeneralRe: win6x_registry_tweak Pin
Dave Kreskowiak23-Oct-17 9:48
mveDave Kreskowiak23-Oct-17 9:48 
GeneralRe: win6x_registry_tweak Pin
Pete O'Hanlon23-Oct-17 9:55
mvePete O'Hanlon23-Oct-17 9:55 
GeneralRe: win6x_registry_tweak Pin
Dave Kreskowiak24-Oct-17 2:56
mveDave Kreskowiak24-Oct-17 2:56 
GeneralRe: win6x_registry_tweak Pin
Pete O'Hanlon23-Oct-17 9:49
mvePete O'Hanlon23-Oct-17 9:49 
QuestionNewbie question - how to access this object Pin
Member 1347915022-Oct-17 13:10
Member 1347915022-Oct-17 13:10 
Hi. I'm new to C#. I really want to learn to write code in a proper way. In the following example i was trying to do this:

1. On Form there is black Panel
2. On this Panel there are three green PictureBoxes
3. Whenever one of these PicureBoxes is clicked, Panel changes its color to red.

Now, the code I've came up with is:

C#
using System;
using System.Drawing;
using System.Windows.Forms;
public class MainForm : Form
{
	public class SomeClass : PictureBox
	{
		public SomeClass()
		{
			this.BackColor = Color.Green;
			this.MouseDown += new System.Windows.Forms.MouseEventHandler(mouseDown);
		}
		public void mouseDown(object sender, MouseEventArgs e)
		{
			panel1.BackColor = Color.Red; // this is problematic; how to access panel1?
		}
	}
	
	Panel panel1 = new Panel();
	SomeClass someObject = new SomeClass();
	SomeClass someObject2 = new SomeClass();
	SomeClass someObject3 = new SomeClass();

	public MainForm()
	{	
		this.Controls.Add(this.panel1);
		this.panel1.Size = new System.Drawing.Size(200, 600);
		this.panel1.BackColor = Color.Black;
		this.panel1.Controls.Add(this.someObject);
		this.panel1.Controls.Add(this.someObject2);
		this.panel1.Controls.Add(this.someObject3);
		this.someObject.Location = new System.Drawing.Point(0, 0);
		this.someObject2.Location = new System.Drawing.Point(0, 100);
		this.someObject3.Location = new System.Drawing.Point(0, 200);
	}

	public static void Main()
	{
		Application.Run(new MainForm());	
	}
}


And the big problem is that I cannot access panel1. What's the most elegant solution to this?
AnswerRe: Newbie question - how to access this object Pin
User 740747022-Oct-17 14:23
User 740747022-Oct-17 14:23 
AnswerRe: Newbie question - how to access this object Pin
OriginalGriff22-Oct-17 19:50
mveOriginalGriff22-Oct-17 19:50 
AnswerRe: Newbie question - how to access this object Pin
BillWoodruff23-Oct-17 4:48
professionalBillWoodruff23-Oct-17 4:48 
GeneralMessage Closed Pin
23-Oct-17 5:51
User 740747023-Oct-17 5:51 
GeneralRe: Newbie question - how to access this object Pin
BillWoodruff24-Oct-17 3:46
professionalBillWoodruff24-Oct-17 3:46 
GeneralMessage Closed Pin
24-Oct-17 12:56
User 740747024-Oct-17 12:56 
GeneralRe: Newbie question - how to access this object Pin
Jim_Snyder27-Oct-17 4:56
professionalJim_Snyder27-Oct-17 4:56 
QuestionAnyone experiencing that, .NET Standard project in VS2017 hanging while compiling Pin
Super Lloyd22-Oct-17 9:42
Super Lloyd22-Oct-17 9:42 
AnswerRe: Anyone experiencing that, .NET Standard project in VS2017 hanging while compiling Pin
Richard MacCutchan22-Oct-17 11:20
mveRichard MacCutchan22-Oct-17 11:20 
QuestionRe: Anyone experiencing that, .NET Standard project in VS2017 hanging while compiling Pin
Super Lloyd22-Oct-17 12:28
Super Lloyd22-Oct-17 12:28 
AnswerRe: Anyone experiencing that, .NET Standard project in VS2017 hanging while compiling Pin
Richard MacCutchan22-Oct-17 20:52
mveRichard MacCutchan22-Oct-17 20:52 
AnswerRe: Anyone experiencing that, .NET Standard project in VS2017 hanging while compiling Pin
jschell23-Oct-17 7:34
jschell23-Oct-17 7:34 
QuestionHow to start a form without being activated? [solved] Pin
alin120-Oct-17 14:48
alin120-Oct-17 14:48 
AnswerRe: How to start a form without being activated? Pin
BillWoodruff20-Oct-17 16:30
professionalBillWoodruff20-Oct-17 16:30 
AnswerRe: How to start a form without being activated? Pin
OriginalGriff21-Oct-17 0:03
mveOriginalGriff21-Oct-17 0:03 
GeneralRe: How to start a form without being activated? Pin
BillWoodruff21-Oct-17 0:27
professionalBillWoodruff21-Oct-17 0:27 
GeneralRe: How to start a form without being activated? Pin
OriginalGriff21-Oct-17 0:41
mveOriginalGriff21-Oct-17 0:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.