Hey Guys,
I am creating a small program to generate cards for my parents company. Each card consists of a Logo, Title, and Description. Since I'm a very independent person and I just started making this without putting much thought into it, I spent an hour learning the basics of the Graphics class, drawing lines, images, e.t.c, and I managed to dynamically generate this card
[Excuse the bad design, I made it simple as my parents aren't the best with adapting to new technologies].
http://i.imgur.com/W8AioFG.png[
^]
The result is how I expected, generated dynamically, I congratulated myself. However, whenever I add another instance of the controls, stuff goes crazy.
I present to you:
http://s23.postimg.org/g8tdlaoex/Such_Doge.gif[
^]
Here's the source, you can hate on the code, but keep in mind I started programming 6 months ago, and I'm 14.However, I do hate ageism at the same time :/. Such Hippocritical.
http://www.mediafire.com/download/rzxj2b17enr5nbj/SuchCardGen.rar[
^]
Here is the relevant part of the code that generates the card.
public partial class Card : UserControl
{
Graphics g;
private string Title, Description;
public Card(string Title, string Description)
{
InitializeComponent();
this.Title = Title;
this.Description = Description;
g = CreateGraphics();
}
private Rectangle DrawBox()
{
Rectangle rect = new Rectangle(4, 4, 323, 204);
g.DrawRectangle(new Pen(Color.Black, 2), rect);
return rect;
}
private void DrawLine(Color c, int sx, int sy, int es, int ey)
{
g.DrawLine(new Pen(c), new Point(sx, sy), new Point(es, ey));
}
public static Image resizeImage(Image imgToResize, Size size)
{
return (Image)(new Bitmap(imgToResize, size));
}
private void DrawTitle(string Text, float FontSize)
{
Rectangle newRect = ClientRectangle;
newRect.Height -= 65;
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
String drawString = Text;
Font drawFont = new Font("Segoe UI", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
g.DrawString(Text, new Font("Segoe UI", FontSize), Brushes.Black, newRect, format);
}
private void DrawDescription(string Text,float FontSize)
{
Rectangle newRect = ClientRectangle;
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
String drawString = Text;
Font drawFont = new Font("Segoe UI", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
g.DrawString(Text, new Font("Segoe UI", FontSize), Brushes.Black, newRect, format);
}
public void RefreshCard(string Titlez, string Descriptionz, float titleFontSizez, float descriptionFontSizez)
{
g.Clear(Color.White );
DrawBox();
AddJaxLogo();
DrawTitle(Titlez, titleFontSizez);
DrawDescription(Descriptionz, descriptionFontSizez);
DrawLine(Color.Black, 120, 67, 195, 67);
}
private void FillCard()
{
DrawBox();
AddJaxLogo();
DrawTitle(Title, 18f);
DrawDescription(Description, 12f);
DrawLine(Color.Black, 120, 67, 195, 67);
}
private void AddJaxLogo()
{
g.DrawImage(resizeImage(Jax_Generator.Properties.Resources.Jax_logo, new Size(89, 64)), 115, 2);
}
private void tmr_Tick(object sender, EventArgs e)
{
FillCard();
tmr.Enabled = false;
}
}
To emulate it, create a user control, drag a timer onto the form, and name it tmr, then assign the appropriate event handlers.
Oh, right, and the question is. Why is it doing that, and how do I fix it?
Thanks guys!