473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Visual C# Drawing is Beneath Everything

23
Hi again,

This problem is a little more complicated, and once again is in C#. I've create a form, with a groupbox, and in it, a picturebox. In the picturebox's paint event, I've drawn a black line through the middle of the picturebox, but the line is behind the picturebox and groupbox.

How do I get the line to be drawn in front of everything? In Visual BASIC, doing the same thing works fine, but in C#, anything that is drawn, is behind all objects and controls...

Sincerely,

Str!ker
Jun 30 '07 #1
5 1257
weaknessforcats
9,208 Expert Mod 8TB
Moving this to the.NET forum.
Jun 30 '07 #2
kenobewan
4,871 Expert 4TB
What code are you using to draw the line?
Jul 1 '07 #3
str1ker
23
Expand|Select|Wrap|Line Numbers
  1. private void pictureBox2_Paint(object sender, PaintEventArgs e)
  2.         {
  3.             int idlePoint;
  4.             idlePoint = this.trackBar1.Value;
  5.  
  6.             Point point1 = new Point(229, 210 - idlePoint);
  7.             Point point2 = new Point(229, 210 - idlePoint);
  8.  
  9.             Graphics graphics;
  10.             graphics = this.CreateGraphics();
  11.             Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
  12.             graphics.DrawLine(pen, point1, point2);
  13.         }
That's the code. I've done similar things in BASIC, and that works, but in C# it doesn't...
Jul 4 '07 #4
str1ker
23
anybody? this is really annoying for me.
Jul 8 '07 #5
The problem is that you used this.CreateGraphics() to obtain a graphics object. This gives you a graphics object at the level of the Form, so your line is appearing on the form.

You want your line to appear on the picturebox, so you shouldn't use this.CreateGraphics(). Instead just use the graphics object that the event args provides you: e.Graphics;

Its always best when in a paint event or OnPaint override to use the provided Graphics object rather than creating your own.

Hope this helps,
Kevin
Jul 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Remon Huijts | last post by:
Hi there, For a very specific service, I have created a PHP script that uses the GD library functions to create a PNG image from a few lines of XML data describing a simple diagram/drawing. It's...
7
by: Skip Hollowell | last post by:
I have what is now a table with a header row and then obviously rows of data beneath. If the data is more than 50 or 6 rows (100px) then the rows will scroll using overflow:auto. This all works...
2
by: fplisa | last post by:
Hi- I have code that dynamically adds 1 to 10 textboxes to a form. The user is asked how many boxes he/she needs. Problem is, I can't get to the events of each box that is added EXCEPT for the...
1
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work...
3
by: Rob Mayo | last post by:
I am working in an environment with 4 developers. 2 groups of 2 people working on the same server on the same web project with no version control management on the web server. Programmers A & B...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
8
by: Will Chamberlain | last post by:
I came across a rather interesting article this morning and thought I'd share. We all know that Visual Studio is a great IDE, but I think we can all agree that it is adds a dramatic change to how...
4
by: Charles | last post by:
Hello Everyone, I have been gettting great feedback from microsoft.public.vc.language group but after doing more searching I think my post should be directed to this group. I am trying to make...
3
by: NoBSWebDesign | last post by:
This is a really interesting problem here. Somehow my Database window got stuck beneath the Access menu bar (the menu bar for the Database window is completely hidden). I cannot move it because I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.