Click here to Skip to main content
15,884,177 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 23:22
Exoskeletor24-Aug-20 23:22 
GeneralRe: How to calculate in c# the possibility of this game Pin
Luc Pattyn24-Aug-20 7:48
sitebuilderLuc Pattyn24-Aug-20 7:48 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor24-Aug-20 23:22
Exoskeletor24-Aug-20 23:22 
GeneralRe: How to calculate in c# the possibility of this game Pin
trønderen26-Aug-20 0:50
trønderen26-Aug-20 0:50 
GeneralRe: How to calculate in c# the possibility of this game Pin
Exoskeletor23-Aug-20 19:23
Exoskeletor23-Aug-20 19:23 
QuestionHow do I load a block on a form at startup Pin
Brian_TheLion22-Aug-20 18:56
Brian_TheLion22-Aug-20 18:56 
AnswerRe: How do I load a block on a form at startup Pin
BillWoodruff22-Aug-20 19:12
professionalBillWoodruff22-Aug-20 19:12 
AnswerRe: How do I load a block on a form at startup Pin
OriginalGriff22-Aug-20 20:48
mveOriginalGriff22-Aug-20 20:48 
Don't just draw the block like that - partly because it'll disappear when you minimize the form or drag another form over the top, and partly because you need to Dispose of all Graphics contexts you create as soon as you are finished with them. The best way of doing that is via a using block:
C#
using (Graphics gs = this.CreateGraphics())
    {
    using (Brush b = new SolidBrush(Color.Red))
        {
        using (Pen p = new Pen(b))
            {
            gs.DrawRectangle(p, Goal);
            ...
            }
        }
    ...
    }
Note that that also applies to Pens, Brushes, and other Graphics elements.

If you want to draw on your form, then handle the Form.Paint event and use the graphics context provided:
C#
private void FrmMain_Paint(object sender, PaintEventArgs e)
    {
    using (Brush b = new SolidBrush(Color.Red))
        {
        using (Pen p = new Pen(b))
            {
            e.Graphics.DrawRectangle(p, Goal);
            }
        }
    }

"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

GeneralRe: How do I load a block on a form at startup Pin
Brian_TheLion23-Aug-20 14:33
Brian_TheLion23-Aug-20 14:33 
AnswerRe: How do I load a block on a form at startup Pin
Luc Pattyn23-Aug-20 2:49
sitebuilderLuc Pattyn23-Aug-20 2:49 
AnswerRe: How do I load a block on a form at startup Pin
Gerry Schmitz23-Aug-20 6:48
mveGerry Schmitz23-Aug-20 6:48 
GeneralRe: How do I load a block on a form at startup Pin
Brian_TheLion24-Aug-20 17:03
Brian_TheLion24-Aug-20 17:03 
QuestionCreating a Windows form program using C# 8.0 Pin
Brian_TheLion22-Aug-20 20:30
Brian_TheLion22-Aug-20 20:30 
SuggestionRe: Creating a Windows form program using C# 8.0 Pin
Richard MacCutchan22-Aug-20 21:05
mveRichard MacCutchan22-Aug-20 21:05 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Brian_TheLion23-Aug-20 0:34
Brian_TheLion23-Aug-20 0:34 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Richard MacCutchan23-Aug-20 2:00
mveRichard MacCutchan23-Aug-20 2:00 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Dave Kreskowiak23-Aug-20 4:07
mveDave Kreskowiak23-Aug-20 4:07 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Brian_TheLion23-Aug-20 14:30
Brian_TheLion23-Aug-20 14:30 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Dave Kreskowiak23-Aug-20 18:38
mveDave Kreskowiak23-Aug-20 18:38 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Brian_TheLion24-Aug-20 16:55
Brian_TheLion24-Aug-20 16:55 
AnswerRe: Creating a Windows form program using C# 8.0 Pin
Mycroft Holmes23-Aug-20 12:22
professionalMycroft Holmes23-Aug-20 12:22 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Brian_TheLion24-Aug-20 16:57
Brian_TheLion24-Aug-20 16:57 
AnswerRe: Creating a Windows form program using C# 8.0 Pin
Richard Deeming23-Aug-20 23:11
mveRichard Deeming23-Aug-20 23:11 
GeneralRe: Creating a Windows form program using C# 8.0 Pin
Brian_TheLion24-Aug-20 17:01
Brian_TheLion24-Aug-20 17:01 
Question{Solved} Find and count duplicates in a list Pin
Acuena20-Aug-20 2:51
Acuena20-Aug-20 2:51 

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.