|
Hi All,
I have created a baseclass by subclassing the Textbox control. I have many forms and want to ensure that the textbox controls all use the same font etc...
I want the statusbar of the form to show information about the control you are currently sat in so for example if it was a phone number it would show the format (99999) 000000. I am trying to set this in the enter event of the baseclass.
So I created an Event and a Delegate on the baseclass something like this:
public event EnterControlHandler EnterControl;
public delegate void EnterControlHandler(string strStatus);
public virtual void OnEnterControl(string strStatus)
{
if (EnterControl != null)
EnterControl(this.StatusText);
}
I then tried to handle the event in the form:
protected void EnterControl(string strStatus)
{
//this.formloader(e.Node.Text);
this.statusForm.Text = strStatus;
}
The problem is the Enter event doesnt seem to fire.
I havent used delegates or events much so i could be using them incorrectly.
Am I going about this the correct way? If so any pointer on what I'm doing wrong?
Many thanks for your time.
Jon
|
|
|
|
|
Are you assigning event handler to EnterControl event? You need to do like:
yourTextBoxObject.EnterControl += EnterControl;
from the form.
|
|
|
|
|
Hello,
I have a compiled dll that contain class "MyClasses.dll".
One of the class is called "class1".
In runtime i need to compile a code that used "class1" and i need to used to compile code as dll in the runtime code. How can i do it?
Example:
1. MyClasses.dll contain class1.
class1 look like this:
delegate double GetRank(class1 c1);
public class1
{
public double Num1;
public double Num2;
public event GetMyRank;
}
2. I want to get a string and build a function in rumtime for sorting. for example the user can write n Textbox "Num1*Num2" and then i want to create this function:
public double GetRank1(class1 c1)
{
return c1.Num1*c1.Num2;
}
3. Compile and Create dll that contain this function.(GetRank1)
4. In runtime load the dll for exmple "MyDll.dll"
5. Initialize each instance of class1 with the event "GetRank1" for "GetMyRank" event. :
class1 c1 = new class1();
...
..
c1.GetMyRank= new GetRank(MyDll.GetRank1);
....
6. And then i want to compare 2 instance of 'class1' by this function.
I Allready try to use CodeDomProvider and CompilerParameters but i need the use the dll "MyClasses.dll" in the CompilerParameters and it does not recognize him:
ErrorText: "The type or namespace name 'MyClasses.dll' could not be found (are you missing a using directive or an assembly reference?)"
The second problem is how to use to compiled code in my code at runtime.
for example:
Assembly a = Assembly.GetAssembly(Type.GetType("GetRank1Class"));
and then try to call the function GetRank1.
How can i solve those problems?
|
|
|
|
|
My experience with this stuff is limited, from what I've done in the past I would say:
1.
you need to add references to all the managed DLL files you need at compile time, hence use
CompilerParameters.ReferencedAssemblies.Add(dllFileName)
2.
you can't use dynamic classes and methods as usual; you need reflection code for every instance and method, such as Assembly.CreateInstance() and Type.GetMember() and MethodInfo.Invoke() ; all of which is cumbersome.
Are you sure you need it? You didn't tell much about the real functionality of your app.
FWIW: I expect you can reduce the hassle by having a fixed interface that works like a contract for your dynamic class; once you get an instance (still through reflection), you should be able to invoke methods in the normal way as long as they are part of that interface.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
hi
IS there a different in WebService programming in 32bit and 64bit ?
under server 2003 (C# programming )
thank's in advance
|
|
|
|
|
AFAIK no. You just need to keep the target platform set as Any CPU.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hello, I`m making in Windows XP a Search Deskband [like the one in Vista] but i have a big problem: don't know how to get the current window address, so that it searches only in current folder and subfolders.
Thank you in advance!
|
|
|
|
|
curtuy wrote: the current window address
address??
could it be Directory.GetCurrentDirectory() you want?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
for a deskband Directory.GetCurrentDirectory() returns "C:\Documents and Settings\My user"
for ex: if i`m in D:\Games i want to get "D:\Games".
[Thanks for your fast responses ]
|
|
|
|
|
What is a window address?
|
|
|
|
|
Microsoft Way 1
Redmond
WA 98052, USA
I are Troll
|
|
|
|
|
window address: in IE is the place where you write a site's path, in Explorer is the current path.
|
|
|
|
|
Sometime back, I found this[^] link. Not that it is the solution to your problem, but I guess this is what you are looking for. Maybe someone who has used this method or is aware about this can help.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks very much .
|
|
|
|
|
Hello,
Im trying to make a multithreaded proxy tester/scanner.
http://i36.tinypic.com/2m5jllf.jpg[^]
here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WebProxyTest
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void Main_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
}
private void btnStart_Click(object sender, EventArgs e)
{
for(int i = 0; i < lstProxies.Items.Count; i++){
string proxy = lstProxies.Items[i].ToString();
string[] proxyinfo = proxy.Split(':');
string proxyhost = proxyinfo[0];
int proxyport = Convert.ToInt32(proxyinfo[1]);
WebProxyTest test = new WebProxyTest(proxyhost, proxyport, "http://google.com/");
ThreadPool.SetMaxThreads(10, 2);
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessProxies), test);
}
}
private void ProcessProxies(object state){
WebProxyTest test = state as WebProxyTest;
test.TestProxy();
lstResults.Items.Add("Result: " + test.ProxyResult);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
namespace WebProxyTest
{
class WebProxyTest
{
private string proxyhost;
private int proxyport;
private string url;
private string proxy_result = "none";
public string ProxyResult {
get {
return proxy_result;
}
set {
proxy_result = value;
}
}
public WebProxyTest(string proxyhost, int proxyport, string url)
{
this.proxyhost = proxyhost;
this.proxyport = proxyport;
this.url = url;
}
public void TestProxy()
{
try
{
WebProxy proxy = new WebProxy(String.Format("http://{0}:{1}/", proxyhost, proxyport), true);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = proxy;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string result = reader.ReadToEnd();
proxy_result = "Done: Got " + result.Length;
System.Windows.Forms.Clipboard.SetText(result);
response.Close();
reader.Close();
}
catch (System.Exception ex)
{
proxy_result = "Error: " + ex.Message;
}
}
}
}
the problem is at this line:
test.TestProxy();
and/or
lstResults.Items.Add("Result: " + test.ProxyResult);
when I call a function/property of the WebProxyTest class I get an exception with something like:
"Error: The current thread is the mode Single Thread Apartment (STA) be brought before OLE calls can be made. Verify that the main function STAThreadAttribute is highlighted."
any ideas?
Thanks in advance
modified on Sunday, October 11, 2009 1:10 PM
|
|
|
|
|
Hi,
there could be two issues:
1.
OptiPlex wrote: CheckForIllegalCrossThreadCalls = false;
IMO is a very bad idea. If you feel a need to disable those checks, something is fundamentally wrong. Please read this article[^].
2.
AFAIK a lot of (all?) COM components (and that includes the Clipboard) require to be handled only by threads that are in a "Single Threaded Apartment", which also is a way to obtain thread safety. You can get things right by either specifying [STAThread] in front of your public static Main() method (which is there by default IIRC), or by setting it explicitly on the relevant thread, using Thread.GetCurrentThread().SetThreadAppartmentState().
[EDIT]
As one can set the AppState only once for a thread, this may not work for ThreadPool threads; so you may have to create your own Thread(s) instead.
[/EDIT]
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
thanks allot for your reply.
I was checking out the link u posted, but it seems like thats for controls/ui operations only.
Now im still looking for other sollutions
thanks again
|
|
|
|
|
As I said earlier, using CheckForIllegalCrossThreadCalls is bad, whatever your app is, as it does not solve anything, it is completely useless (that is what the article is about). So you should fix that; and then do something about STA as I indicated.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The project we are working on for school requires us to create a windows form in Visual Studio 2008. We have written the code for the database manager, dbHelper, employee and employee factory class. We do not know how to call the appropriate methods to the form. We are not allowed to put any code in the form other than get a appropriate methods. We are not using WPF.
|
|
|
|
|
Depends on the solution structure. If the UI is in separate project, then you will need to add the reference to the other projects in the UI project and the call the method.
In case everything is in same solution, you can call methods marked public/internal through creating objects of respective classes. In case of static methods, you can directly call the method using class name. If you have different namespaces in the solution, use fully qualified names.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hello,
The KeyDown even is:
<Occurs when a key is pressed while the control has focus.>
What if i want to see ALL key presses? not only when the control has the focus?
Thanks
|
|
|
|
|
|
On the main form there will be a property called Key Preview . Set that to true and the main forms KeyPress or KeyDown event (I'm not sure which) will be fired before the active control gets the event.
This property is only available on a windows form however, I'm quite sure it's not on any controls.
My current favourite word is: Sammidge!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
How can I do the following number 4 and 5 task using client server socket programming?
1. Client send a query as regular text to the server. [I can do this]
2. Server get the SQL from the client. [I can do this]
3. Server execute the query(Select statement). [I can do this]
4. Server return the query result as datatable or dataset to the client [How can I do this]
5. Client get the datatable or dataset and display to the client side.[How can I do this]
|
|
|
|
|
1. Don't write everything in bold. It's a plain message, so it's wise to use plain text.
dokhinahaoa wrote: Server return the query result as datatable or dataset to the client
Serialize it into XML, that should do the trick.
dokhinahaoa wrote: Client get the datatable or dataset and display to the client side.
Deserialize your dataset
I are Troll
|
|
|
|