Reputation: 133
I am a C# newbie and have encountered a problem in my homework.
I have a panel in 'Form1.cs' called panel3.
Now, I have a class called 'Staff' and I want to add a method in Staff to draw a sequence of lines underneath each other. These lines must be added and shown in panel3 (found in Form1.cs).
How can I do this please? Thank you.
I have something like this in the "Staff.cs":
My problem is how I am going to invoke it in Form1_Load event? What parameters should I pass to it?
I want the 'Draw' method to draw the lines in panel3 found in 'Form1.cs'.
Thanks.
Edit
Thanks a lot for your help :) I have solved it now thanks to you :)
Upvotes: 0
Views: 294
Reputation: 11820
public class Staff : Panel
{
public const int kOffset = 30;
public const int kSignatureOffset = 25;
public const int kStaffSpacing = 70;
public const int kBarSpacing = 7;
const int kNumMeasuresOnAStaff = 4;
public const int kStaffInPixels = 800;
public int staffIndex { get; set; }
public Staff()
{
}
protected override void OnPaint(PaintEventArgs e)
{
int yPos = kOffset + staffIndex * kStaffSpacing;
for (int bars = 0; bars < 5; bars++)
{
e.Graphics.DrawLine(Pens.Black, 0, yPos, kStaffInPixels, yPos);
yPos += kBarSpacing;
}
}
}
Upvotes: 1