I try to define a line with the length of 1 unit (1 pixel) that is, in fact,
just a point on the screen. But when I draw it with a wide pen with the
appropriate StartCap and EndCap (Round), it will appear as a dot.
I can think of a way to define a 1-pixel long line but it is ugly and
clumsy.
I subtract .5 from the given pixel's X and Y coordinate for the first
System.Drawing. PointF structure, and add .5 to the other PointF stucture. It
seems to work (see the code below), but it doesn't feel good.
Is there a standard way to obtain a line with unit length 1?
//namespace OnePixelLine
namespace OnePixelLine
{
//class Form
class Form:System.Win dows.Forms.Form
{
//one integer type point that won't produce output
System.Drawing. Point point0=new System.Drawing. Point(50,50);
//two integer type points that produce 2-pixels long line
System.Drawing. Point point1=new System.Drawing. Point(100,100);
System.Drawing. Point point2=new System.Drawing. Point(101,101);
//two float type points that produce 1-pixel long line, but it is ugly
System.Drawing. PointF pointf1=new System.Drawing. PointF(149.5f,1 49.5f);
System.Drawing. PointF pointf2=new System.Drawing. PointF(150.5f,1 50.5f);
//a pen
System.Drawing. Pen pen=new System.Drawing. Pen(System.Draw ing.Color.Red);
//constructor
Form()
{
//widen pen. Remove this to check the length of the lines
pen.Width=9;
//set StartCap and EndCap both to Round
pen.StartCap=Sy stem.Drawing.Dr awing2D.LineCap .Round;
pen.EndCap=Syst em.Drawing.Draw ing2D.LineCap.R ound;
//prepare for paint
Paint+=new System.Windows. Forms.PaintEven tHandler(OnPain t);
}
//OnPaint
void OnPaint(object a,System.Window s.Forms.PaintEv entArgs b)
{
//this outputs nothing
b.Graphics.Draw Line(pen,point0 ,point0);
//this outputs a line 2 pixels long
b.Graphics.Draw Line(pen,point1 ,point2);
//this outputs a line 1 pixel long, but it is clumsy
b.Graphics.Draw Line(pen,pointf 1,pointf2);
}
//Main
public static void Main()
{
System.Windows. Forms.Applicati on.Run(new Form());
}
}
}
Apr 17 '06
13 2391
>> SetStyle ( System.Windows. Forms.ControlSt yles.AllPaintin gInWmPaint| System.Windows. Forms.ControlSt yles.DoubleBuff er| System.Windows. Forms.ControlSt yles.ResizeRedr aw| System.Windows. Forms.ControlSt yles.UserPaint, true );
Ever heard of the using statement? :-)
The using statement? Not using it makes it easier to look up different
classes since I know where they reside. I am an ardent typer :-)
"Martijn Mulder" <i@m> wrote in message
news:44******** *************** @news.wanadoo.n l... SetStyle ( System.Windows. Forms.ControlSt yles.AllPaintin gInWmPaint| System.Windows. Forms.ControlSt yles.DoubleBuff er| System.Windows. Forms.ControlSt yles.ResizeRedr aw| System.Windows. Forms.ControlSt yles.UserPaint, true );
Ever heard of the using statement? :-)
The using statement? Not using it makes it easier to look up different classes since I know where they reside. I am an ardent typer :-)
It would make everything else harder though, typing, reading, maintaining.
:-)
Michael
>>>> SetStyle ( System.Windows. Forms.ControlSt yles.AllPaintin gInWmPaint| System.Windows. Forms.ControlSt yles.DoubleBuff er| System.Windows. Forms.ControlSt yles.ResizeRedr aw| System.Windows. Forms.ControlSt yles.UserPaint, true );
Ever heard of the using statement? :-)
The using statement? Not using it makes it easier to look up different classes since I know where they reside. I am an ardent typer :-)
It would make everything else harder though, typing, reading, maintaining. :-)
I don't agree.
- Typing: My editor makes it very easy to copy a line. All editors do
- Reading: When a long name shows up (i.e. System.Drawing. ..,
System.Windows. Forms...) I know it is SDK-defined, all else is user defined.
The eye is wandering for repitition, for redundancy
- Maintaining: Maintaining code is a nightmare, any kind of code
Never using using (no, never!) makes the code self-documenting, so to speak.
Only thing is that I am new to C# so I start out typing javax.swing... when
I mean System.Drawing. ..
"Martijn Mulder" <i@m> wrote in message
news:44******** *************** @news.wanadoo.n l... I don't agree.
- Typing: My editor makes it very easy to copy a line. All editors do
You can't disagree there. You type more than me, full stop.
- Reading: When a long name shows up (i.e. System.Drawing. .., System.Windows. Forms...) I know it is SDK-defined, all else is user defined. The eye is wandering for repitition, for redundancy
You read more also. Personally I found your code much more difficult to
read. I know Point is in System.Drawing so don't need to be reminded over
and over. Besides, where it is isn't so important to me that I need see it
every time it is used.
- Maintaining: Maintaining code is a nightmare, any kind of code
That's a cop out. Some code is easier to maintain than other.
Never using using (no, never!) makes the code self-documenting, so to speak. Only thing is that I am new to C# so I start out typing javax.swing... when I mean System.Drawing. ..
I doubt you'll find many developers who agree :-)
Michael This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rolf Brauser |
last post by:
Hello,
is it possible to draw a one pixel line around every cell in a table?
with "border: 1px solid; " just the outer tableborder ist concerned ?
thanks for any help
rolf
|
by: unknown |
last post by:
some one can give me a portable source codes that color a pixel?
(env *nix)
--
unknown
|
by: TomHL |
last post by:
hello,
- I have a Bitmap Object named: bmp1
- I already have the numerical values of:red,blue and green colors + I have
the X and Y cordinates.
How do I set the pixel value via safe code on the bmp1 object?
(the pixel location based on the X & Y values and it's color based on the
red,blue and green values the I already have)
|
by: Rob T |
last post by:
This seems like a really stupid question, but here it goes........
is there a command to draw a single pixel?
The closest I can get is to draw a line that is 2 pixels wide, or do create
another image that's 1x1 with the color of the pixel, then do a DrawImage to
insert that image into the 'master' image...which seems like a huge waste!
Thanks.
|
by: walter.alex |
last post by:
November 16 2005 -- The recent launch of the new 5 year advertising
solution from MillionPixelClick.com means the pixel advertising craze
will continue unabated. Selling advertising space by the pixel the new
form of advertising is proving popular with both clients and providers
alike.
Designed to boost traffic, an image is placed on MillionPixelClick.com
with a link to your website. These pixels will be visible for at least
5 years....
| |
by: Chaos |
last post by:
As my first attempt to loop through every pixel of an image, I used
for thisY in range(0, thisHeight):
for thisX in range(0, thisWidth):
#Actions here for Pixel thisX, thisY
But it takes 450-1000 milliseconds
I want speeds less than 10 milliseconds
|
by: sadegh |
last post by:
I am using VC++6. I want to draw some simple shapes (e.g. line,
circle, pixel) on a dialog box. How can I do this? Thanks a lot
|
by: marss |
last post by:
<hr style="height:1px"/does not fit because although a line looks
like it has 1 pixel with but there are empty spaces above and below
line. It can be seen if place two HR elements beside.
<hr style="height:1px"/>
<hr style="height:1px"/>
I tried also <div style="height:1px;font-size:1px;background-
color:black;"></divbut a line was 2 pixel thick :(
|
by: ofiras |
last post by:
Hi,
I made a "Paint" program, but I couldn't find a method to paint 1
pixel using graphic state ("Graphics g =
Graphics.FromHwnd(this.Handle);")
How can I paint 1 pixel?
I guess I can make a Bitmap, change one pixel color and show it, but
I'm sure there is another way of doing it.
Please help,
Ofir.
|
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: 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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |