T
Tommy Lang
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
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