Jump to content

Declaring something at run-time

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
How can I declare instance of PrintDocument class at run-time???

#2
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
Just like you would for any other class.

PrintDocument myPrintDocument = new PrintDocument();


#3
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
that's at design time

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
This might be kinda what you're looking for, I think:
runtime declaration with variable type
sudo rm -rf /

#5
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
the best example for what i mean is when you have a 2 buttons on your form with click on first button you have 4 radio buttons and when you click on second button you have 6 radio buttons

#6
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
well, in your example of adding controls to a form, you don't need to design them persay.. one option is to do something like this


List<Control> controls = new List<Control>();


then on the button click...


RadioButton rbn = new RadioButton();

rbn.Text = "some text";

//set other properties


controls.Add(rbn);


this.Controls.Add(rbn); //this as in reference to the form


rbn.Top = top_location;

rbn.Left = left_location;



#7
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
tnx a lot




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users