Click here to Skip to main content
15,886,806 members
Home / Discussions / C#
   

C#

 
GeneralRe: Web service problem - error when binding to datagrid Pin
Gindi Bar Yahav20-Jun-09 6:55
Gindi Bar Yahav20-Jun-09 6:55 
QuestionHow do I check whether the "X" button in the top right corner was clicked? Pin
Etienne_12320-Jun-09 2:39
Etienne_12320-Jun-09 2:39 
AnswerRe: How do I check whether the "X" button in the top right corner was clicked? Pin
Luc Pattyn20-Jun-09 2:42
sitebuilderLuc Pattyn20-Jun-09 2:42 
AnswerRe: How do I check whether the "X" button in the top right corner was clicked? Pin
0x3c020-Jun-09 2:45
0x3c020-Jun-09 2:45 
GeneralRe: How do I check whether the "X" button in the top right corner was clicked? Pin
Etienne_12321-Jun-09 11:52
Etienne_12321-Jun-09 11:52 
QuestionNeed Easy Insert Method Pin
M Riaz Bashir20-Jun-09 2:30
M Riaz Bashir20-Jun-09 2:30 
AnswerRe: Need Easy Insert Method Pin
Manas Bhardwaj20-Jun-09 3:11
professionalManas Bhardwaj20-Jun-09 3:11 
QuestionGDI+ how to not painting the background image [modified] Pin
cppwxwidgetsss20-Jun-09 1:44
cppwxwidgetsss20-Jun-09 1:44 
Hello everybody
I have a Form and I use the GDI+ to have a User Interface
I have a Button(just an image) that should be repainted when it is clicked
and I use a flag at the mouse event handler to know when the button is clicked
and in the OnPaint method I check it FIRST, and if the flag was True I don't paint
the BackGroundImage, because it is painted before (at the startup of the Form)
but I don't know why that BackGroundImage is gone when the event occures
and only my button and the BackColor of the Form is shown
=>>note: I don't want to use BackGroundImage because I think it will paint it all the times that the Form is repainted, and it is process intensive
Thank you
P.S: If you want to read this code better you can copy/paste it in VS.NET and
select all the code and use CTRL + (K) then CTRL + (F) to format the code
in a good format to be more readable
here is the OnPaint method:

<br />
 protected override void OnPaint(PaintEventArgs e)<br />
        {<br />
            if (LanguageTraining)<br />
            {<br />
                //dc.FillRectangle(Brushes.White, new Rectangle(744, 617, 248, 42));<br />
                dc.DrawImage(ButtonSelectedBlue, LanguageButtonBounds);<br />
                LanguageTraining = false;<br />
                base.OnPaint(e);<br />
                return;<br />
            }<br />
            base.OnPaint(e);<br />
            Graphics dc = e.Graphics;<br />
            dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
           <br />
            <br />
            dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
            dc.DrawImage(piccy, piccyBounds);<br />
            dc.DrawString("Language Training", ButtonFont, TextBrush, new Point(755, 625));<br />
           <br />
            <br />
        }<br />


Here is all the code

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace paintImage<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        private bool LanguageTraining = false;<br />
        private Point MouseClickPosition;<br />
        private readonly Brush TextBrush = Brushes.White;<br />
        private readonly Font ButtonFont = new Font("alefba", 18,FontStyle.Bold);<br />
<br />
        readonly Image piccy;<br />
        readonly Image ButtonSelectedBlue;<br />
        readonly Image ButtonSelectedGreen;<br />
        private readonly Point[] piccyBounds;<br />
        private readonly Point[] LanguageButtonBounds;<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
            piccy = Image.FromFile(@"C:\pics\page1.png");<br />
            <br />
            ButtonSelectedBlue = Image.FromFile(@"C:\pics\Button Selected Blue.png");<br />
            ButtonSelectedGreen = Image.FromFile(@"C:\pics\Button Selected Green.png");<br />
            AutoScrollMinSize = piccy.Size;<br />
            piccyBounds = new Point[3];<br />
            LanguageButtonBounds = new Point[3];<br />
            <br />
            const int resolutionX = 1024; //the x dimension of the display resolution<br />
            const int resolutionY = 768; //the y dimension of the display resolution<br />
<br />
           <br />
            piccyBounds[0] = new Point(0, 0);<br />
            piccyBounds[1] = new Point(resolutionX, 0);<br />
            piccyBounds[2] = new Point(0, resolutionY);<br />
<br />
            LanguageButtonBounds[0] = new Point(744, 617);<br />
            LanguageButtonBounds[1] = new Point(992, 617);<br />
            LanguageButtonBounds[2] = new Point(744, 659);<br />
<br />
        }<br />
<br />
        protected override void OnPaint(PaintEventArgs e)<br />
        {<br />
            if (LanguageTraining)<br />
            {<br />
                //dc.FillRectangle(Brushes.White, new Rectangle(744, 617, 248, 42));<br />
                dc.DrawImage(ButtonSelectedBlue, LanguageButtonBounds);<br />
                LanguageTraining = false;<br />
                base.OnPaint(e);<br />
                return;<br />
            }<br />
            base.OnPaint(e);<br />
            Graphics dc = e.Graphics;<br />
            dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
           <br />
            <br />
            dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
            dc.DrawImage(piccy, piccyBounds);<br />
            dc.DrawString("Language Training", ButtonFont, TextBrush, new Point(755, 625));<br />
           <br />
            <br />
        }<br />
        protected override void OnKeyUp(KeyEventArgs e)<br />
        {<br />
            base.OnKeyUp(e);<br />
            if (e.KeyCode == Keys.Escape)<br />
                this.Close();<br />
        }<br />
        protected override void OnMouseDown(MouseEventArgs e)<br />
        {<br />
            base.OnMouseDown(e);<br />
            MouseClickPosition = new Point(e.X, e.Y);            <br />
        }<br />
        protected override void OnMouseClick(MouseEventArgs e)<br />
        {<br />
            base.OnMouseClick(e);<br />
            if (MouseClickPosition.X > 755 && MouseClickPosition.X < 1024 && MouseClickPosition.Y > 625 && MouseClickPosition.Y < 768)<br />
            {<br />
                Invalidate();<br />
                LanguageTraining = true; //means that only language training button should be repainted<br />
            }<br />
        }<br />
        private void Form1_Load(object sender, EventArgs e)<br />
        {<br />
<br />
        }<br />
    }<br />
}<br />
<br />
<br />


modified on Saturday, June 20, 2009 7:56 AM

AnswerRe: GDI+ how to not painting the background image Pin
Luc Pattyn20-Jun-09 1:57
sitebuilderLuc Pattyn20-Jun-09 1:57 
GeneralRe: GDI+ how to not painting the background image [modified] Pin
cppwxwidgetsss20-Jun-09 2:11
cppwxwidgetsss20-Jun-09 2:11 
QuestionIP address in to varient Pin
sudhi16419-Jun-09 20:17
sudhi16419-Jun-09 20:17 
AnswerRe: IP address in to varient Pin
Christian Graus19-Jun-09 20:22
protectorChristian Graus19-Jun-09 20:22 
QuestionGetting Message: "Couldn't Update; Currently Locked" in mdb Pin
honeyashu19-Jun-09 20:03
honeyashu19-Jun-09 20:03 
AnswerRe: Getting Message: "Couldn't Update; Currently Locked" in mdb Pin
Christian Graus19-Jun-09 20:07
protectorChristian Graus19-Jun-09 20:07 
Questiongetting the parent control from a child control at runtime. Pin
Xandip19-Jun-09 19:32
Xandip19-Jun-09 19:32 
AnswerRe: getting the parent control from a child control at runtime. Pin
Christian Graus19-Jun-09 19:46
protectorChristian Graus19-Jun-09 19:46 
GeneralRe: getting the parent control from a child control at runtime. Pin
Xandip19-Jun-09 19:50
Xandip19-Jun-09 19:50 
QuestionSelecting Color Scheme from withing app Pin
Nigel Mackay19-Jun-09 19:03
Nigel Mackay19-Jun-09 19:03 
AnswerRe: Selecting Color Scheme from withing app Pin
Christian Graus19-Jun-09 19:45
protectorChristian Graus19-Jun-09 19:45 
GeneralRe: Selecting Color Scheme from withing app Pin
Nigel Mackay19-Jun-09 20:49
Nigel Mackay19-Jun-09 20:49 
QuestionOpen link in new Tab when Mouse Middle Click... Pin
Baeltazor19-Jun-09 18:36
Baeltazor19-Jun-09 18:36 
AnswerRe: Open link in new Tab when Mouse Middle Click... Pin
Christian Graus19-Jun-09 19:44
protectorChristian Graus19-Jun-09 19:44 
GeneralRe: Open link in new Tab when Mouse Middle Click... Pin
Baeltazor19-Jun-09 21:25
Baeltazor19-Jun-09 21:25 
GeneralRe: Open link in new Tab when Mouse Middle Click... Pin
Christian Graus19-Jun-09 21:56
protectorChristian Graus19-Jun-09 21:56 
GeneralRe: Open link in new Tab when Mouse Middle Click... Pin
Baeltazor19-Jun-09 22:33
Baeltazor19-Jun-09 22: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.