Click here to Skip to main content
15,919,358 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to write to file using FileStream class Pin
Rudolf Jan20-Jul-07 7:12
Rudolf Jan20-Jul-07 7:12 
Questionbinding combo box with array Pin
monuSaini19-Jul-07 20:08
monuSaini19-Jul-07 20:08 
AnswerRe: binding combo box with array Pin
Michael Sync19-Jul-07 20:30
Michael Sync19-Jul-07 20:30 
GeneralRe: binding combo box with array Pin
monuSaini19-Jul-07 20:39
monuSaini19-Jul-07 20:39 
Questiondetect mouseclick in an area Pin
cyn819-Jul-07 19:34
cyn819-Jul-07 19:34 
AnswerRe: detect mouseclick in an area Pin
Christian Graus19-Jul-07 19:42
protectorChristian Graus19-Jul-07 19:42 
GeneralRe: detect mouseclick in an area Pin
cyn819-Jul-07 19:53
cyn819-Jul-07 19:53 
GeneralRe: detect mouseclick in an area Pin
Martin#19-Jul-07 20:05
Martin#19-Jul-07 20:05 
Hello Christian,

Christian Graus wrote:
Why do you have a member graphics object ? I don't see how that's ever a good idea.

I normaly never need to draw on Images, but I was interested by a question here on the forum.
The task is to Draw on the BackgroundImage of a panel.
I did a little test project and thought this is a good idea:
private Graphics panelGraphics = null;
private Pen leftPen = new Pen(Color.Red,2);
private Pen rightPen = new Pen(Color.White,2);
private Point oldPosition;
private bool init=false;

private void panel2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if((e.Button == MouseButtons.Left) || (e.Button == MouseButtons.Right))
    {
        Pen actPen;
        if(e.Button == MouseButtons.Left)
        {
            actPen = leftPen;
        }
        else
        {
            actPen = rightPen;
        }

        if(panel2.BackgroundImage==null)
            panel2.BackgroundImage= new Bitmap(panel2.Width, panel2.Height);

        if(panelGraphics==null)
            panelGraphics = Graphics.FromImage(panel2.BackgroundImage);

        if(init)
        {
            Point newPostion = new Point(e.X,e.Y);
            panelGraphics.DrawLine(actPen, oldPosition, newPostion);
            Refresh();
        }
        init=true;

        oldPosition = new Point(e.X,e.Y);
    }
}

private void panel2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
    init=false;
}

private void panel2_MouseLeave(object sender, System.EventArgs e)
{
    init=false;
}

As you can see I also used a member graphics object, and now I'm curious what you think of it.

Thanks for your time!

P.S.: I would Dispose all the IDisposable members in the Dispose method of the form, off course!



All the best,

Martin

AnswerRe: detect mouseclick in an area Pin
Martin#19-Jul-07 19:53
Martin#19-Jul-07 19:53 
GeneralRe: detect mouseclick in an area Pin
cyn819-Jul-07 19:57
cyn819-Jul-07 19:57 
Questionproblem with SQL server Pin
prasadbuddhika19-Jul-07 19:21
prasadbuddhika19-Jul-07 19:21 
AnswerRe: problem with SQL server Pin
originSH19-Jul-07 21:55
originSH19-Jul-07 21:55 
QuestionCustom Tab Control Pin
T.EDY19-Jul-07 16:50
T.EDY19-Jul-07 16:50 
AnswerRe: Custom Tab Control Pin
Martin#19-Jul-07 19:15
Martin#19-Jul-07 19:15 
QuestionSocket communication (Winsock), interop ... Pin
devvvy19-Jul-07 15:30
devvvy19-Jul-07 15:30 
AnswerRe: Socket communication (Winsock), interop ... Pin
originSH19-Jul-07 21:59
originSH19-Jul-07 21:59 
GeneralRe: Socket communication (Winsock), interop ... Pin
devvvy20-Jul-07 3:15
devvvy20-Jul-07 3:15 
GeneralRe: Socket communication (Winsock), interop ... Pin
originSH20-Jul-07 4:10
originSH20-Jul-07 4:10 
GeneralRe: Socket communication (Winsock), interop ... Pin
devvvy20-Jul-07 22:31
devvvy20-Jul-07 22:31 
GeneralRe: Socket communication (Winsock), interop ... Pin
originSH23-Jul-07 12:10
originSH23-Jul-07 12:10 
AnswerRe: Socket communication (Winsock), interop ... Pin
pbraun20-Jul-07 9:12
pbraun20-Jul-07 9:12 
GeneralRe: Socket communication (Winsock), interop ... Pin
devvvy24-Jul-07 5:26
devvvy24-Jul-07 5:26 
QuestionPropertyGridItem -Dynamic Value Updates Pin
mastmast19-Jul-07 13:19
mastmast19-Jul-07 13:19 
Question.xml documentation Pin
jon-8019-Jul-07 11:19
professionaljon-8019-Jul-07 11:19 
AnswerRe: .xml documentation Pin
DavidNohejl19-Jul-07 11:33
DavidNohejl19-Jul-07 11:33 

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.