C
C#•5mo ago
Aubrey

Cuboid not being drawn

The cube works perfectly fine.
No description
No description
16 Replies
Aubrey
Aubrey•5mo ago
BlazeBin - tywbbdfnunmk
A tool for sharing your source code with the world!
Buddy
Buddy•5mo ago
You must override or subscribe to OnPaint event
Aubrey
Aubrey•5mo ago
huh
Buddy
Buddy•5mo ago
You cannot simply draw once because if the window is redrawn the graphics will disappear https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.onpaint?view=windowsdesktop-8.0
Aubrey
Aubrey•5mo ago
idk if im just stupid but the microsoft sites r so hard for me to understand 😭 maybe its just cus im a beginner
Buddy
Buddy•5mo ago
It has examples if you scroll catlaugh
Aubrey
Aubrey•5mo ago
the examples r equally as confusing 😭
Buddy
Buddy•5mo ago
yourcontrol.Paint += YourMethod; is how you subscribe to an event. The method will be called when the event has been called / invoked. The paint event will be called when the control needs a repaint, like when you resize or move the window.
Aubrey
Aubrey•5mo ago
but it doesnt get resized or moved
Buddy
Buddy•5mo ago
YourMethod Can be
private void YourMethod(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Create a local version of the graphics object for the PictureBox.
Graphics g = e.Graphics;

// Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control",
fnt, System.Drawing.Brushes.Blue, new Point(30,30));
// Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, pictureBox1.Top,
pictureBox1.Right, pictureBox1.Bottom);
}
private void YourMethod(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Create a local version of the graphics object for the PictureBox.
Graphics g = e.Graphics;

// Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control",
fnt, System.Drawing.Brushes.Blue, new Point(30,30));
// Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, pictureBox1.Top,
pictureBox1.Right, pictureBox1.Bottom);
}
No matter You can do this pictureBox1.Paint += YourMethod; Which will subscribe to the paint event. And just follow the code that was posted above which is the example in Microsofts documentation.
Aubrey
Aubrey•5mo ago
i dont wanna seem stupid, but what is "YourMethod" here? 😭 still havent figured out how to fix this 😭
Buddy
Buddy•5mo ago
I took a look at your code further, you are doing an early return if it isn't "cube" Meaning only "cube" execute You must think logically return means it will stop execution and return a value, if the return has been hit, anything after a return will be ignored. != not equals == equals
if (comboBoxShape.SelectedItem != "Cube")
{
// Anything that isn't "Cube" will return early, meaning it will not draw anything.
return;
}
if (comboBoxShape.SelectedItem != "Cube")
{
// Anything that isn't "Cube" will return early, meaning it will not draw anything.
return;
}
Aubrey
Aubrey•5mo ago
oh my god. thank you so much i didnt know thats what the code did that helps alot i was just told to use != without further explanation neither did i know what return did 😭
Buddy
Buddy•5mo ago
blobthumbsup
Aubrey
Aubrey•5mo ago
BlazeBin - xifyvlcqfimg
A tool for sharing your source code with the world!
Aubrey
Aubrey•5mo ago
done now :3 @Net🅱orking is🎄save me pls thank you so much again