drawimage help please

Post your questions regarding programming in C# in here.
4 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

drawimage help please
Dummy1912
it seems that this won't work :(

what are we doing wrong even i have no clue it seems working fine in vb.net this way but not in c#
Code: Select all
if (_clicked == false)
      {
          g.DrawImage(pictureBox2.Image, new Rectangle(0, 0, 39, 41));
      }
      else
      {
          g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, 39, 41));
      }
Error is
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
thank you
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: drawimage help please
XTechVB
Make sure that g is initialized like so
Code: Select all
Graphics g = e.Graphics;
//-- Or like this
Graphics g = this.CreateGraphics();
And pictureBox1 and pictureBox2 have an image set. And also try not to draw images in DesignMode (it tends to slow down the Designer).
Last edited by XTechVB on Wed Feb 12, 2014 8:52 pm, edited 2 times in total.
You can find me on Facebook or on Skype mihai_92b
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: drawimage help please
smashapps
make sure you have this at the very top of your class code, then everything else below it.
Code: Select all
public Form1()
        {
            InitializeComponent();
        }
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: drawimage help please
Dummy1912
thanks you #smashapps this did the job :)
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
4 posts Page 1 of 1
Return to “General coding help”