473,387 Members | 3,684 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,387 software developers and data experts.

GDI+

Hi,
I need some help. I am trying to draw cards.
I am using DrawRectagle() to draw upp the outlining of the card. Then
I fill the card with white color FillRectangle(). Then with DrawString
I can write the cards name at the top and bottom of the card.
So far everything works great. I can draw up one, two or more cards
and it looks great. Just like I want it to.
But now to my problem...
The cards lacks the symbol(clubs, heart, spade, diamond) in the center
of the card. I've managed to draw up all the different symbols using
gdi+ with DrawPolygon. For ex diamonds:
****** ex code ******
//Create pens and brushes
Pen penBlack = new Pen(Color.Black);
Pen penRed = new Pen(Color.Red);
SolidBrush bsWhite = new SolidBrush(Color.White);
SolidBrush bsRed = new SolidBrush(Color.Red);

//Draw rectangle and fill it
Rectangle r = new Rectangle(this.Property_X, this.Property_Y,
this.Property_Width, this.Property_Height);
e.DrawRectangle(penBlack, new Rectangle(this.Property_X,
this.Property_Y, this.Property_Width, this.Property_Height));
e.FillRectangle(bsWhite, this.Property_X+1, this.Property_Y+1,
this.Property_Width-2, this.Property_Height-2);

//Write name on card in top and bottom, centered
Font TheFont = new Font("Arial", 8, FontStyle.Bold);
float CenterOfCard = this.Property_Width / 2;
SizeF StringSize = e.MeasureString(base.m_Namn, TheFont);
float StartPosition = CenterOfCard -(StringSize.Width / 2);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y+5);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y + (this.Property_Height - 20));

//Draw symbol diamond
Point[] point = new Point[]{new Point(79, 109),new Point(90, 95), new
Point(101, 109), new Point(101, 110),new Point(90, 123), new Point(79,
110), new Point(79, 109)};

e.DrawPolygon(penRed, point);
e.FillPolygon(bsRed, point);

//Dispose pens and brushes
penBlack.Dispose();
penRed.Dispose();
bsWhite.Dispose();
bsRed.Dispose();
****** code ******
This will draw the diamond symbol at the specified(point) place on a
form.
It works good as long as the card is in the upper left corner.
The way I have implemented it I can move the cards around on the
screen, with text and it still looks good.
But I dont get how to do the math with the symbols, since they have
many points.
When the sympol consists of many points (like clubs), how do I
calculate so that it always stays centered within the rectangle drawn
with DrawRectagle?

Hope that I explained it clearly.
Thanks Tommy
Nov 15 '05 #1
3 2544
n!
> When the sympol consists of many points (like clubs), how do I
calculate so that it always stays centered within the rectangle drawn
with DrawRectagle?


The graphics object supports a transformation matrix which you can use to
translate (amongst other things) your paths, so that they appear at a
different location. For simplistic transformations, the graphics object
provides support methods to make it easier for you:

using System.Drawing;
using System.Drawing.Drawing2D;

private void DrawMySymbol( Graphics graphics, float x, float y )
{
GraphicsState oldState = graphics.Save();

graphics.TranslateTransform( x, y );

// Draw symbol as usual here...

graphics.Restore( oldState );
}

Note there is a newsgroup specifically for questions regarding drawing with
the .NET framework (microsoft.public.dotnet.framework.drawing).

n!
Nov 15 '05 #2
If i were you i would forget about drawing the cards with GDI.

Unless you have some special reason for doing it this way.

I would use bitmaps of card images instead and "paint" them on the
rectangular card areas.

"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78**************************@posting.google.c om...
Hi,
I need some help. I am trying to draw cards.
I am using DrawRectagle() to draw upp the outlining of the card. Then
I fill the card with white color FillRectangle(). Then with DrawString
I can write the cards name at the top and bottom of the card.
So far everything works great. I can draw up one, two or more cards
and it looks great. Just like I want it to.
But now to my problem...
The cards lacks the symbol(clubs, heart, spade, diamond) in the center
of the card. I've managed to draw up all the different symbols using
gdi+ with DrawPolygon. For ex diamonds:
****** ex code ******
//Create pens and brushes
Pen penBlack = new Pen(Color.Black);
Pen penRed = new Pen(Color.Red);
SolidBrush bsWhite = new SolidBrush(Color.White);
SolidBrush bsRed = new SolidBrush(Color.Red);

//Draw rectangle and fill it
Rectangle r = new Rectangle(this.Property_X, this.Property_Y,
this.Property_Width, this.Property_Height);
e.DrawRectangle(penBlack, new Rectangle(this.Property_X,
this.Property_Y, this.Property_Width, this.Property_Height));
e.FillRectangle(bsWhite, this.Property_X+1, this.Property_Y+1,
this.Property_Width-2, this.Property_Height-2);

//Write name on card in top and bottom, centered
Font TheFont = new Font("Arial", 8, FontStyle.Bold);
float CenterOfCard = this.Property_Width / 2;
SizeF StringSize = e.MeasureString(base.m_Namn, TheFont);
float StartPosition = CenterOfCard -(StringSize.Width / 2);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y+5);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y + (this.Property_Height - 20));

//Draw symbol diamond
Point[] point = new Point[]{new Point(79, 109),new Point(90, 95), new
Point(101, 109), new Point(101, 110),new Point(90, 123), new Point(79,
110), new Point(79, 109)};

e.DrawPolygon(penRed, point);
e.FillPolygon(bsRed, point);

//Dispose pens and brushes
penBlack.Dispose();
penRed.Dispose();
bsWhite.Dispose();
bsRed.Dispose();
****** code ******
This will draw the diamond symbol at the specified(point) place on a
form.
It works good as long as the card is in the upper left corner.
The way I have implemented it I can move the cards around on the
screen, with text and it still looks good.
But I dont get how to do the math with the symbols, since they have
many points.
When the sympol consists of many points (like clubs), how do I
calculate so that it always stays centered within the rectangle drawn
with DrawRectagle?

Hope that I explained it clearly.
Thanks Tommy

Nov 15 '05 #3
Hi Tommy

See either my article at codeproject

http://www.codeproject.com/csharp/drawcardscp1.asp

or my site for some help, (this is a work in progress).

http://www.publicjoe.f9.co.uk/csharp/card00.html

Cheers

Mike

"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78**************************@posting.google.c om...
Hi,
I need some help. I am trying to draw cards.
I am using DrawRectagle() to draw upp the outlining of the card. Then
I fill the card with white color FillRectangle(). Then with DrawString
I can write the cards name at the top and bottom of the card.
So far everything works great. I can draw up one, two or more cards
and it looks great. Just like I want it to.
But now to my problem...
The cards lacks the symbol(clubs, heart, spade, diamond) in the center
of the card. I've managed to draw up all the different symbols using
gdi+ with DrawPolygon. For ex diamonds:
****** ex code ******
//Create pens and brushes
Pen penBlack = new Pen(Color.Black);
Pen penRed = new Pen(Color.Red);
SolidBrush bsWhite = new SolidBrush(Color.White);
SolidBrush bsRed = new SolidBrush(Color.Red);

//Draw rectangle and fill it
Rectangle r = new Rectangle(this.Property_X, this.Property_Y,
this.Property_Width, this.Property_Height);
e.DrawRectangle(penBlack, new Rectangle(this.Property_X,
this.Property_Y, this.Property_Width, this.Property_Height));
e.FillRectangle(bsWhite, this.Property_X+1, this.Property_Y+1,
this.Property_Width-2, this.Property_Height-2);

//Write name on card in top and bottom, centered
Font TheFont = new Font("Arial", 8, FontStyle.Bold);
float CenterOfCard = this.Property_Width / 2;
SizeF StringSize = e.MeasureString(base.m_Namn, TheFont);
float StartPosition = CenterOfCard -(StringSize.Width / 2);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y+5);
e.DrawString(base.m_Namn, TheFont, bsRed, this.Property_X +
StartPosition, this.Property_Y + (this.Property_Height - 20));

//Draw symbol diamond
Point[] point = new Point[]{new Point(79, 109),new Point(90, 95), new
Point(101, 109), new Point(101, 110),new Point(90, 123), new Point(79,
110), new Point(79, 109)};

e.DrawPolygon(penRed, point);
e.FillPolygon(bsRed, point);

//Dispose pens and brushes
penBlack.Dispose();
penRed.Dispose();
bsWhite.Dispose();
bsRed.Dispose();
****** code ******
This will draw the diamond symbol at the specified(point) place on a
form.
It works good as long as the card is in the upper left corner.
The way I have implemented it I can move the cards around on the
screen, with text and it still looks good.
But I dont get how to do the math with the symbols, since they have
many points.
When the sympol consists of many points (like clubs), how do I
calculate so that it always stays centered within the rectangle drawn
with DrawRectagle?

Hope that I explained it clearly.
Thanks Tommy

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: **ham | last post by:
I know that's an old dirty issue; GDI+ almost -the slowest part of the framework - has bothered many developers using it in animations. Even in managed C++ the performance is awful. Now, any dude...
6
by: James dean | last post by:
I have heard that the video drivers in GDI+ are a big performance issue. But is this only an issue with something like Games Programming i think...is this wrong?. What about a drawing application...
1
by: James dean | last post by:
Could someone explain how this works. I think the graphics card is used to do blitting and drawing shapes like rectangles. How does it draw using the Graphics card on the PC and why is this feature...
6
by: James dean | last post by:
I want a good site that will show clearly how much more functionality GDI+ has. I cannot seem to find anything other than sites that list "some" of the new functionality that GDI+ offers. A...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
0
by: Brian Keating | last post by:
hi there i've a test program that creates a treeview and destroys it over and over, i keep track of the gdi object count for the process and see if they are ok. However when i switch on...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
5
by: Jonathan Boivin | last post by:
Hi, I've got some problems with loading bills using a bill usercontrol I built. If I load all current bills in my test environment (156) everything is fine once, but repeating the operation...
1
by: Chris Dunaway | last post by:
When working with GDI+, calling the CreateGraphics method to draw on a control has normally been frowned upon and it is always emphasized to dispose of pens and brushes and other GDI objects lest...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...

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.