I created a Windows Form Project using VS.net.
I'm trying to draw a line between two points.
(Plotting a graph, dynamically)
This is the code I have so far:
What do I have to do to actually see the line painted on
my form?
private: System::Void button1_Click(S ystem::Object *
sender, System::EventAr gs * e)
{
Graphics* g;
Pen* myPen = new Pen(Color::Red) ;
myPen->Width = 5;
g->DrawLine(myPen , 1, 1, 45, 65);
} 2 1936
You are going to need a pointer to the graphics context of your form.
Typically you might want to use something like the Paint event, it gets
called any time your form needs to be redrawn for any reason - you could
call the Paint eventHandler from the button click function.
void frmPaint(Object * sender, System::Windows ::Forms::PaintE ventArgs * e)
{
Graphics * grfx = e->Graphics;
grfx->DrawLine(myPen , 1, 1, 45, 65);
}
Add something like this to your form constructor to tie the forms Paint
event to the frmPaint function.
this->add_Paint(ne w PaintEventHandl er(this, frmPaint));
Adios,
January
"Coralin Feierbach" <an*******@disc ussions.microso ft.com> wrote in message
news:02******** *************** *****@phx.gbl.. . I created a Windows Form Project using VS.net. I'm trying to draw a line between two points. (Plotting a graph, dynamically) This is the code I have so far: What do I have to do to actually see the line painted on my form?
private: System::Void button1_Click(S ystem::Object * sender, System::EventAr gs * e) { Graphics* g; Pen* myPen = new Pen(Color::Red) ; myPen->Width = 5; g->DrawLine(myPen , 1, 1, 45, 65); }
"Coralin Feierbach" <an*******@disc ussions.microso ft.com> wrote in
news:02******** *************** *****@phx.gbl: private: System::Void button1_Click(S ystem::Object * sender, System::EventAr gs * e) { Graphics* g; Pen* myPen = new Pen(Color::Red) ; myPen->Width = 5; g->DrawLine(myPen , 1, 1, 45, 65); }
in your example, replace with :
//
Graphics* g = this->CreateGraphics () ;
// This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Long |
last post by:
Hello, (total GDI newbie)
I'm having trouble drawing just a simple line to display in a picturebox. I
just want a straight, dotdash line.
I have two methods, one works and one doesn't (it cause an exception to be
thrown):
This one works but it's not the results I want.
private void CreateImage1()
{
|
by: Stuart Norris |
last post by:
Dear Readers,
I am attempting to draw box around some text using unicode on
multiline label. The label is forty characters wide and 12 lines deep.
I have been trying to draw a box around text (centered in the label)
on this label.
My font on this label is Courier new - hence fixed width character
cells.
|
by: Peter Oliphant |
last post by:
There doesn't seem to be any documentation on how to create and/or use an
instance of System::Drawing::Graphics. On-line MSDN talks about this class,
and says:
" The Graphics class provides methods for drawing objects to the display
device. A Graphics object is associated with a specific device context. "
Great. So how about explaining HOW to do this? Or perhaps a code example? Or
at least a CONSTRUCTOR (or some explanation on how to...
|
by: Metallicraft |
last post by:
I have a vb6 application. On the main form is a picture
box with one or two images and several pieces of text
displayed in it. These are created on the fly using gdi32
routines that are all in a referenced, custom dll. I call
a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll's print routine
draws to the hdc and it shows up in the picturebox
perfectly.
I would like to do a similar thing...
|
by: davetelling |
last post by:
I am not a programmer, I'm an engineer trying to make an interface to a
product I'm designing. I have used C# to make a form that interrogates the
unit via the serial port and receives the data. I want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
| |
by: lab3terch |
last post by:
Imports System.Drawing.Graphics
Public Class Form1
Inherits System.Windows.Forms.Form
Dim x1, y1, x2, y2 As Integer
Dim red, black, blue, green, orange As Color
Dim x, y, w, h As Integer
Dim rectangle, freehand As Graphics
Dim line As Graphics
Dim wide, n As Integer
|
by: dongarbage |
last post by:
Hi there,
I'm very much a C# novice.
How do you do freehand drawing on a panel with a mouse in c#?
Thanks,
Don
|
by: Macias |
last post by:
Hi,
Please help me, how I can make a line drawing on PictureBox similar to
MS paint. I thinking about this: click and hold button, move mouse and
relase button.
I'm trying useing this g.DrawLine(..), but I have a lot of line.
In C++ is a parameter XORPUT, but in C# I can't find it.
|
by: Chris Dunaway |
last post by:
On May 8, 1:11 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
I'm afraid that I can't offer anything more than what you have learned
on your own. I only suggested that class because I have seen the
original poster's question many times in various forums and that is,
invariably, the answer that is given. I haven't delved too deeply
into the subject myself.
Chris
|
by: raylopez99 |
last post by:
I have a logical drawing space much bigger than the viewport (the
screen) and I'd like to center the viewport (the screen) to be at the
center of the logical drawing space. After following the excellent
transforms specified on Bob Powell's site, I still wonder if there's
an easier way of centering it than the following procedure?
Here is what I do now (it's awkward but it works):
1) I follow the transforms specified on Bob Powell's...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |