Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Change text size of a dynamic button

help tic tac toe

  • Please log in to reply
4 replies to this topic

#1 aazamsajid

aazamsajid

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 08 April 2012 - 08:46 AM

i am working on tic tac toe game and im creating dynamic buttions now i want change text's size of a dynamic buttion'text
how can i change ...?

void Form1_Click(object sender, EventArgs e)
	    {
		    Button bt = (Button)sender;
		    if (flag == 0)
		    {
			    bt.Text = "x";
			    bt.Text.Size = new System.Drawing.Size(30, 20);//this line i am using please correct it with a correct one.
			    flag = 1;
		    }
		    else
		    {
			    bt.Text = "0";
			    flag = 0;
		    }
		   
		    bt.Enabled = false;
		    t++;
		    check();
		    if (t == 9)
		    {
			    MessageBox.Show("Draw");
			    reset();
		    }
	    }

  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 08 April 2012 - 09:26 AM

What do you mean by you want to change size of text of a dynamic button? You mean want to change the font size of the button text? The following code you wrote shall not compile as there is no 'Size' property of String (Text is a string type property of button).

bt.Text.Size = new System.Drawing.Size(30, 20);//this line i am using please correct it with a correct one.

If you want to change font size for button text, you can do the following way.

bt.Font.Size = 10;

  • 0

#3 aazamsajid

aazamsajid

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 08 April 2012 - 09:45 AM

if i use this the following error occurng

1 Property or indexer 'System.Drawing.Font.Size' cannot be assigned to -- it is read only
  • 0

#4 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 08 April 2012 - 09:48 AM

Sorry for the mistake. Yes, Size is readonly property for Font. Please use code like following to change font.

bt.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

  • 0

#5 aazamsajid

aazamsajid

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 08 April 2012 - 09:53 AM

bt.Font = new Font("Georgia", 16);

this is my solution...thx dear
  • 0





Also tagged with one or more of these keywords: help, tic tac toe

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download