Lets say i have a text box and i type picturebox.visible = false; then i press a button to execute it.
and My Picturebox is not visible now.
so How do i run that command since it was in a text box???
Execute a Command from a TextboxI want to Execute a Command from a textbox..
Page 1 of 1
7 Replies - 2114 Views - Last Post: 19 July 2009 - 02:49 PM
Replies To: Execute a Command from a Textbox
#2
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 12:22 AM
What exactly are you trying to do? What's the role of the PictureBox control? It is not visible, and you want to set it to visible by using a command?
#3
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 12:36 AM
This is what i'm trying to do.
I have a picturebox in my form and it is visible now.
i also have 1 button and 1 textbox.
so i run my program and i type picturebox.visible=false then i press my button to execute.
And the Result is that picturebox is hidden now.
so what i'm asking is, do someone know the code that can make that thing happen since i use textbox to make the code.
I have a picturebox in my form and it is visible now.
i also have 1 button and 1 textbox.
so i run my program and i type picturebox.visible=false then i press my button to execute.
And the Result is that picturebox is hidden now.
so what i'm asking is, do someone know the code that can make that thing happen since i use textbox to make the code.
#4
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 01:19 AM
You'll have to learn more about Reflection and dynamic code compilation (System.CodeDom.Compiler is a namespace you are looking for in this case).
Also please note, [rules][/rules]
Also please note, [rules][/rules]
#6
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 02:42 AM
#7
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 04:22 AM
I decided to give this a shot using C# which I'm more familiar with. I hope it helps you even though the programming language is wrong.
I made a form and filled it with the input (shown on attachment) and used this code behind the button_click event:
As a result new form modal was opened with title "Hello". The code needs a lots of adjusting for it to become more useful.
Sorry for the C# code in VB.NET forum and the lack of comments. I hope that could help you a bit.
I made a form and filled it with the input (shown on attachment) and used this code behind the button_click event:
private void button2_Click(object sender, EventArgs e) {
CSharpCodeProvider vProvider = new CSharpCodeProvider();
ICodeCompiler vCompiler = vProvider.CreateCompiler();
CompilerParameters vParams = new CompilerParameters();
vParams.GenerateExecutable = false;
vParams.GenerateInMemory = true;
vParams.ReferencedAssemblies.Add("System.dll");
vParams.ReferencedAssemblies.Add("System.Data.dll");
vParams.ReferencedAssemblies.Add("System.Deployment.dll");
vParams.ReferencedAssemblies.Add("System.Drawing.dll");
vParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
string vCode = "";
vCode += "using System;";
vCode += "public class " + txtClassName.Text;
vCode += "{";
vCode += "public void " + txtMethodName.Text + "(" + txtMethodParam.Text + " vParam)";
vCode += "{";
vCode += richTextBox1.Text;
vCode += "}";
vCode += "}";
CompilerResults vResults = vCompiler.CompileAssemblyFromSource(
vParams, vCode);
if (vResults.Errors.Count == 0) {
var vNewClass = vResults.CompiledAssembly.CreateInstance(txtClassName.Text);
vNewClass.GetType().GetMethod(txtMethodName.Text).
Invoke(vNewClass, new[] { "Hello" });
}
}
As a result new form modal was opened with title "Hello". The code needs a lots of adjusting for it to become more useful.
Sorry for the C# code in VB.NET forum and the lack of comments. I hope that could help you a bit.
Attached image(s)
#8
Re: Execute a Command from a Textbox
Posted 19 July 2009 - 02:49 PM
[quote name='Yaroslav94' date='19 Jul, 2009 - 01:42 AM' post='706742']
[quote name='ZevhEr' post='706723' date='19 Jul, 2009 - 12:28 AM']
Thanks Man.
couldn't u use the change text event?
??? cant u use tht???
thnk me if i helped!
Yes. That's help. Thanks. But that is not what i mean.
I didn't write Picturebox1.visible=false in my form code.
I just write it in my text box and run it.
And if i change the text box text to -> Picturebox1.visible=true
It can make the Picture box show.
So That text box is just like a form code where we type our code in.
[quote name='ZevhEr' post='706723' date='19 Jul, 2009 - 12:28 AM']
Thanks Man.
couldn't u use the change text event?
if textbox1.text = "picturebox1.visible = false" then picturebox1.visible = false end if
??? cant u use tht???
thnk me if i helped!
Yes. That's help. Thanks. But that is not what i mean.
I didn't write Picturebox1.visible=false in my form code.
I just write it in my text box and run it.
And if i change the text box text to -> Picturebox1.visible=true
It can make the Picture box show.
So That text box is just like a form code where we type our code in.
This post has been edited by ZevhEr: 19 July 2009 - 02:54 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|