|
You mean you want to track how many instances of the class have been created so far? That's easy, just add a static variable that is incremented in the constructor. Something like
class Foo
{
static int counter;
public Foo() { counter++; ...}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi!
This will give you the number of instances in the current AppDomain only.
If you start the program twice or have your class loaded into different AppDomains, the counter will be initialized to 0 for every AppDomain.
If you really want to know how many instances there are computer-wide, a different approach will be needed.
Regards,
mav
|
|
|
|
|
I have a web browser control on Win form, using Visual C#. I open a Word document in it using control.Navigate..., everythings works fine.
Now I want to get the text that is selected in the control, but nothing works. I try:
_web.Focus();
SendKeys.Send("^c");
but nothing is on a clipboard.
Also this:
_web.ExecWB(SHDocVw.OLECMDID.OLECMDID_COPY, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
but nothing on the clipboard as well.
Anybody has the solution on how to get the text that is selected in the web browser control?
Thanks.
|
|
|
|
|
Hi I have seen the similar problem in my application too. If anyone knows, please let us know. TIA.
|
|
|
|
|
hello everybody!
Please i want to develop editor for C# of my own and i want to integrate the cache of the dot net studio in my editor like when i want for example to open static method in a class for example.
<br />
int my_number = int.Parse("String to parse");<br />
When i write int and follow it with dot it gives me all avialable static methods for this class or when i want to construct new class by reference for example
<br />
Connection myconnection = new connection();<br />
I want when i refer to myconnection and follow it with dot to give me all avialable methods for this class "Dot notation" in vsstudio i know that this is involved for the cache of the studio but i want to use this cache and even when i want to create html file to include also this cache with dot notation . the same as the studio i know that it is easy to do but i don't know how it will work
I implemented full compiler for vsstudio family but i want to use this cache also with dot notation in this project any help about this please .even some programmers do it before isharpdevelop.net develop the same editor but i want to develop the same for my own programming any help about this please
Please reply to me please
Miss With The Best And Die Like The Rest
|
|
|
|
|
|
Code completion is really complicated.
When you want to provide it for classes and methods the user writes, you need to write your own C# parser.
The lookup rules can get really complicated. Your example is easy, you just need to use your parser to find the local variable, but what if it's a field or property from an inherited class?
What if it's a method call of an overloaded method? (Math.Abs(6).<Completion for integer> but Math.Abs(6.0).<Completion for double>)
You can take a look at how I've done it for the SharpDevelop IDE[^].
-- modified at 3:52 Sunday 25th September, 2005
|
|
|
|
|
hi to all,
as part of my apps startup i would like to test for local LAN connectivity as it uses tcp protocol for remoting, this can obviously also include a VPN.
i would like to test for tcp connectivity, so i tried this to my server which i know responds to ping and i get FAIL.
is this the best way or can i check the network adapter instead, also the app may be run as a user who does not have priveleges to start stop services etc.,
can anyone please help?
kind regards,
g00fy
<br />
internal void CheckLANConnectivity()<br />
{<br />
this.initLabel.Text = "Checking Network Connectivity ... ";<br />
this.Refresh();<br />
<br />
try<br />
{<br />
TcpClient client = new TcpClient();<br />
client.Connect("10.0.0.1", 7);<br />
this.initLabel.Text = "Network Connectivity ... PASS ";<br />
}<br />
catch<br />
{<br />
this.initLabel.Text = "Network Connectivity ... FAIL ";<br />
}<br />
}<br />
|
|
|
|
|
Hi!
This won't work because ping uses ICMP echo request packages, not TCP connections to check for connectivity.
(Btw. you don't even have to try UDPClient, this won't work either.:->)
If you want the code for a real ping, take a look here[^]
Otherwise, you could try to connect to the real server object you're trying to use later on to check whether it exists and is reachable.
Regards,
mav
|
|
|
|
|
thank you,
i do try catch later for the remoting but at startup, the client doesnt know about any servers.
is it possible to broadcast for remoting servers? i am trying this at the moment ?
if i cant get it i will try your ping link and see how i go.
thank you for response
g00fy
|
|
|
|
|
simple, i used this
<br />
internal void CheckLANConnectivity()<br />
{<br />
this.initLabel.Text = "Checking Network Connectivity ... ";<br />
this.Refresh();<br />
<br />
string host = System.Configuration.ConfigurationSettings.AppSettings["host"];<br />
Debug.WriteLine("host from config file: " + host);<br />
<br />
IPHostEntry serverHE;<br />
try<br />
{<br />
serverHE = Dns.GetHostByName(host); <br />
this.initLabel.Text = "Network Connectivity ... PASS ";<br />
Debug.WriteLine("hostbyname: " + serverHE.ToString());<br />
}<br />
catch(Exception)<br />
{<br />
this.initLabel.Text = "Network Connectivity ... FAIL ";<br />
}<br />
}<br />
simple but works, just need to know its there
kind regards,
g00fy
|
|
|
|
|
Careful, here you only get the information that your DNS knows about a computer with the given name!
This doesn't mean the computer is running and reachable.
One way to check for a server (at least if you're in a LAN) could be to broadcast a UDP request on the subnet and have the server answer this request with information on how it's reachable.
Regards,
mav
|
|
|
|
|
yeah thanks mav,
i realised that after it failed on me once so i did exactly as you suggested
thanks again
g00fy
|
|
|
|
|
I am using following code to populate my windows datagrid. I have a boolean colunm for credit card transactions [called CCTransaction]. I would like this column to be a check box column insted of it showing 0s and 1s. Could you please help me with this. Thanks and advace.
private void frmEntryDataGrid_Load(object sender, System.EventArgs e)
{
string sqlString = "SELECT ID, CheckNumber, CCTransaction, Comments, Total, Amount, DateTimeVal FROM tbl_Total_Control";
SqlDataAdapter da = new SqlDataAdapter(sqlString, SqlConn);
DataSet ds = new DataSet();
try
{
da.Fill(ds,"tbl_Total_Control");
dgTC.DataSource = ds.Tables["tbl_Total_Control"];
}
catch(SqlException exSQL)
{
MessageBox.Show(this,exSQL.Message,"DATABASE ERROR!",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
catch(Exception exc)
{
MessageBox.Show(this,exc.Message,"ERROR!",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
if(SqlConn.State == ConnectionState.Open)
{
SqlConn.Close();
}
}
}
|
|
|
|
|
|
If someone could take a look at this code and see what I'm doing wrong I'd appreciate it. If I place the code that converts the TextBox values to cmplxValue1's //SEE COMMENT**1,**2, in the try block I get a
line from the (0,0) in the ClientRect, to the center of the ClientRect.
If I try to convert in the button click I get an unhandled exception.
//////////////////////////////////////////////////////////////////////////
** Exception Text **************
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info)
at System.Double.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Convert.ToDouble(String value)
at ComplexTest2.Form1.DrawComplexNumber(Graphics g, Complex2 cmplxValue1) in c:\documents and settings\xyz\my documents\software engineering\c#_projects\c#_ tempfiles\complextest2\form1.cs:line 340
//////////////////////////////////////////////////////////////////////////
//code on Form1 linked to Complex2 class-> yes I hav Set/Get properties for all...
//Member fields.
public Pen[] activePen = new Pen[] { new Pen( Color.Blue ), new Pen( Color.Green ), new Pen(Color.Red) };
Complex2 c_xy = new Complex2(250, 250); //OK
protected Complex2 cmplxValue1 = new Complex2(0,0); //OK
protected Complex2 cmplxValue2 = new Complex2(0,0); //OK
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//Graphics g = this.CreateGraphics();
//Pen [] cmplxPen = new Pen []{new Pen(Color.Red, 2), new Pen(Color.Green, 2), new Pen(Color.Blue, 2)};
DrawGraphRectF(e.Graphics);//WORKS
DrawXYAxes(e.Graphics);//WORKS
DrawGraphXandYTicks(e.Graphics);WORKS
if(cmplxValue1.DrawLine1)//bool flag
//MessageBox.Show(Convert.ToString(xIndent + graphRect.Width/2)); //OK as Test for Runtime Values = 250, 250
DrawComplexNumber(e.Graphics, cmplxValue1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void complex_1OK_Click(object sender, System.EventArgs e)
{
//
try
{
/*bool flag*/cmplxValue1.DrawLine1 = true;
this.Invalidate();
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void DrawComplexNumber(Graphics g, Complex2 cmplxValue1)
{
this.cmplxValue1.Real = Convert.ToDouble(this.textComplex_1Real.Text); //SEE COMMENT ABOVE** 1
this.cmplxValue1.Imaginary = Convert.ToDouble(this.textComplex_1Imaginary.Text); //SEE COMMENT ABOVE **2
g.DrawLine(activePen[0], (float)c_xy.Real, (float)c_xy.Imaginary, (float)cmplxValue1.Real, (float)cmplxValue1.Imaginary);
}
|
|
|
|
|
"Input string was not in a correct format."
You are trying to convert a value that can not be interpreted as a number.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I have a control array and have tested the control type to find a listview. I want to assign the control to a listview with something like below.
System.Windows.Forms.ListView olistview = new ListView();
olistview = g_control_array[i];
C# does not like this and i get a cannot convert control to listview. Is there a way to achieve this as I can't find anything to help do this.
The only othe way I can think of is to establish an array of listviews as well but i would prefer not to do this unless I have to.
Thanks for any help.
Stephen
|
|
|
|
|
You want to read a ListView out of the control array?
Then you won't have to create a new one. The control array can contain any control, so you have to tell the compiler "I'm sure this item is a ListView":
ListView olistview;
olistview = (ListView)g_control_array[i];
|
|
|
|
|
Worked. Thanks.
Too easy!
Stephen
|
|
|
|
|
Hi
I've got the following code:
I get the error: The node to be inserted is from a different document context.
I've already imported the, so whats wrong?
XmlNode toNode(string input)
{
XmlDocument a = new XmlDocument();
a.LoadXml(input);
return a.DocumentElement;
}
XmlNode tmp = toNode("<string></string>");
lines[linenumber].ImportNode(tmp, true);
lines[linenumber].AppendChild(tmp);
cheers
|
|
|
|
|
The ImportNode methods returns the node.
---
b { font-weight: normal; }
|
|
|
|
|
Howdy all,
I have a problem in trying to get application domains setup and hope somebody there could point me in the right direction. I came across code from gotdotnet that is called apploader (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=2C78AB99-E190-4A4A-A91A-F7DE1DE78E5B[^]. I am trying to implement a Windows Forms that creates an application domain, using the SpawnedApp class as per in the source for apploader, load the process into the newly created appdomain. Funny thing is this, in the AppLoader as per gotdotnet.com it's Main Thread attribute is [MTAThread], Winforms are by default [STAThread], Apploader worked a treat - loaded assemblies fine and worked, but I've tried to get it to work under winforms which fails. It loads the assemblies under the newly created appdomain on a winform and executes up to a certain point then it crashes. Is there something I'm missing or something that is not well documented regarding creating app domains in a winforms application?? Would threading have anything to do with it as that's my hunch. I click on a button which fires a thread, then creating a new instance of spawnedapp class with the full path to the assemblies/config file which in turn creates a thread and executes it in the new appdomain.
I've been tearing my hair out in frustration .Maybe my sig sums it all up!!
Hope you could help me out on this one!
Kind regards,
Tom Brennan.
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|
|
Hi Nick, Tom here, I have an application that has a lot of assemblies, and from the console AppLoader, it loads all the assemblies fine. It is from a WinForm Application that it loads partial assemblies then it keels over and dies with threadabort exception...The reason I wish to load it into an app domain is one of security. I was using the SpawnedApp Class from the AppLoader...
Thanks Nick for your reply!
Tom Brennan.
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|