|
There are thousands of articles here, a lot of them about C#.
some examples[^]
|
|
|
|
|
Hi all,
Is it possible to do down-casting? If so, how?
Example:
Public class A
{
}
Public class B : A
{
}
Void main()
{
A a = new A();
B b = (B)a; // <-- down-cast, a run time error.
}
Thanks in advance.
|
|
|
|
|
No you can not: it would require an existing object (a) to suddenly become larger
(in case B has more data members, more methods, than A); this is impossible.
The one time "downcasting" is allowed is when reducing the capabilities, as in
int i=1234567;
short s=(short)i;
|
|
|
|
|
i need to a event for my form as lostfocus
123
|
|
|
|
|
Control.LostFocus
and
Form : Control
|
|
|
|
|
the form is not has loastfocus
123
|
|
|
|
|
Form extends Control
|
|
|
|
|
I've been looking at Matias' Half Keyboard and 503 Keyboard (http://www.matias.ca/halfkeyboard/index.php) and it seems like a rather neat idea. However, I'm not willing to spend $100 to find out I don't like it. So, I decided to try making a program/windows service that would intercept any keystroke, and via a configurable mapping, pass the mapped key on to windows. The remapping of keys, I can do. What I need help on is how to trap keyboard signals from getting to windows, and then sending the ones I want through. If anyone has suggestions, pointers, or links to articles about this kind of thing, please share.
I might consider working with others on this project as well. I've always wanted to try a colaborative project, and put out some open-source apps.
A soft glow comes from the pit in the darkness.
The clicking noise become faster - and louder.
A wind begins to stir up from the pit, as the
creature flexes it's wings, preparing for flight.
You stare into the pit, and hear a voice say
in your mind, "If you survive the encounter,
declare it to the world."
The Code Demon Rises.
|
|
|
|
|
You will need to install keyboard hook. Search google and/or codeproject for this term and you will find what you need.
|
|
|
|
|
To reproduce, run the code.
Observed: Form is shown
Expected: message box should displayed.
How to fix ?
Andrus.
using System;<br />
using System.Windows.Forms;<br />
using System.IO;<br />
<br />
class main {<br />
<br />
[STAThreadAttribute()]<br />
<br />
public static void Main() {<br />
File.Delete("c:\\test");<br />
using (FileSystemWatcher watch = new FileSystemWatcher()) {<br />
watch.Path = "c:\\";<br />
watch.Filter = "test";<br />
watch.Created += new FileSystemEventHandler(OnChanged);<br />
watch.Deleted += new FileSystemEventHandler(OnChanged);<br />
watch.Changed += new FileSystemEventHandler(OnChanged);<br />
watch.EnableRaisingEvents = true;<br />
}<br />
FileStream oFs = new FileStream("c:\\test", FileMode.CreateNew, <br />
FileAccess.ReadWrite);<br />
StreamWriter oWriter = new StreamWriter(oFs);<br />
oWriter.Flush();<br />
oWriter.Close();<br />
oFs.Close();<br />
File.Delete("c:\\test");<br />
Application.Run(new Form());<br />
}<br />
<br />
static void OnChanged(object sender, FileSystemEventArgs e) {<br />
MessageBox.Show(e.FullPath + e.ChangeType.ToString());<br />
}<br />
}
Andrus
|
|
|
|
|
Hi,
AndrusM wrote: using (FileSystemWatcher watch = new FileSystemWatcher())
so you dispose of the FileSystemWatcher and expect it to continue working for you ?
|
|
|
|
|
Dear all,
I've got a problem that I just cannot figure out. I must have tried just about everything. I'm hoping that one of you can help me out here.
My main application has got a form referenced, like this :
private Control control1;
This will allow me to call a method inside the form Control , like this :
private void Click(Object sender, EventArgs e)<br />
{<br />
control1.Method();<br />
}
Works perfect. The method on the form Control is executed.
The problem :
I created another form , that I call from inside the form Control :
private void Click_button(Object sender, EventArgs e)<br />
{<br />
ChildForm child = new ChildForm();<br />
child.Show;<br />
}
In that child form I also have got the same Control form referenced, because I want to call the same method exactly the same way as I would from the main application :
private Control control1
and a method to call the method on the Control form.
private void InvokeMethodOnControl()<br />
{<br />
Control.Hello = "a value";<br />
control1.Method();<br />
}
Only the value Control.Hello is passed back to the Control form ( in which I have a public string referenced ( public static string Hello; ) but the Method ( control1.Method() ) is not executed.
Can anyone tell me what I am doing wrong ? .. this is giving me a headache.
Kind regards,
|
|
|
|
|
Hi Rick,
I cant tell from the available code, please show more.
What is Method() supposed to do ? How are you sure it does not execute ?
(are you logging ? single-stepping ? what ?)
Is there a try-catch surrounding the call to InvokeMethodOnControl() ?
Are you showing all exceptions if any (as opposed to just throwing them away) ?
You might want to add another Control.Hello2="something"; in InvokeMethodOnControl().
|
|
|
|
|
even i m not sure from the code given by u
copy the whole code and paste it over here so that i may be able to answer u correctly
currently i can just guess that instead of declaring it as private Control control1;
just declare it as
public Control control1;
|
|
|
|
|
Rick van Woudenberg wrote: private void InvokeMethodOnControl()
{
Control.Hello = "a value";
control1.Method(); <-insert breakpoint here
}
Have you tried to set up breakpoint and step into InvokeMethodOnControl? What is happening?
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Hi Guys,
Thank you all for trying to help me I highly appreciate it ; However, it's extremely hard to explain what I mean. So I hacked together a little testapp that demonstrates the error. It's attached to this post and it's zipped. Just run the binary, and you'll know what I mean.
http://cc786011-b.eo1.fl.home.nl/download/files/TestApp.rar[^]
Cheers,
|
|
|
|
|
the variable "f2" seems to occur exactly twice in the entire solution:
once in Form3.cs at line 24: f2.Method(); // This will give an object reference error
once in Form3.designer.cs at line 74: public Form2 f2;
I am not surprised by a NullReferenceException !
|
|
|
|
|
Luc,
I agree , but Form2 form2 = new Form2() , and then form2.Method(); is obviously not going to work. I already have Form2 open, and I don't want to start a new instance of Form2.
So how, in your opinion am I suppose to call the method on the Form2 that is already open .
Any input is appreciated.
Cheers,
|
|
|
|
|
Hi Rick,
your "problem" is the standard issue of passing references around.
if a Form3 object has to operate on an existing Form2 object, it needs a reference to said
Form2 object.
There are many ways to get this done:
- pass the reference when constructing the Form3 object, in your case that could mean:
Form3 form3 = new Form3(this);
This means Form3 needs a constructor that takes a Form2 and stores it in a
data member (your existing f2 could serve that purpose; a private one suffices).
- pass the reference by setting a public variable:
Form3 form3 = new Form3();
form3.f2=this;
fomr3.Show();
using public data members (f2) is not recommended since now anyone can read/write them,
resulting in code that may become hard to understand and maintain.
- pass the reference by adding and using a public property:
Form3 form3 = new Form3();
form3.F2=this;
fomr3.Show();
and inside Form3 add:
public Form2 F2 { set { f2=value;}}
this is the recommended way: the property exists for a specific purpose, and since
it is public, it deserves a descriptive comment (triple slash).
Hope this helps.
Added:
whatever approach, you may want to test f2 against null before using it:
if (f2!=null) f2.Method();
And there are still other ways of acting on external objects; they would use events
and delegates.
-- modified at 7:36 Saturday 16th June, 2007
|
|
|
|
|
Hi Respected Sirs,
sir i have to develop a unicode symbol dialog like in MS Word , i have done it , i have a panel in my form and again a panel inside first panael i m drawing rectangles in this second panel , i have a combobox for all the languages , now when i click in combobox it shows me all the languages and drwas the characters now when i click on a language in combobox and click on the second panel it doesn't shows me the characters in the area where combobox is i mean the drop area of combobox which is over the second panel . pls help to get rid of this problem.
Pravo
|
|
|
|
|
hi sirs,
i m praveen a new c# programmer , i have to develop a chat server in c# using Socket not TcpListener , now i don't know how to make my socket which can listen infinite number of clients i can do it with infinite while loop but its not working pls provide me some code , how to do it .
Thanx a lot for all of u .
Pravo
|
|
|
|
|
Hi
I think you all viewed that in "My Computer" window (WinXP) at very side some frames are there.
These frames/Groups are scrollable and moveable automatically.
Is there any C# equivalent frame. I love to use it in my application.
Reply please;
Regards.
Syed Shahid Hussain
|
|
|
|
|
|
Thanks a lot Dear Friend. I really need it. Now I'll check it that how optimized that control is because I've seen a pannel control before that had some threading problem......
Any way really thanks for ur assistance.
God Bless You.
Syed Shahid Hussain
|
|
|
|
|
What would be the output of following question
<code>
using System;
namespace Statements
{
class Class1
{
public int Value = 0;
}
class Test
{
static void Main()
{
Class1 e = new Class1();
Class1 f = e;
e.Value = 1;
f.Value = 5;
Console.WriteLine(e.Value.ToString() + " " + f.Value.ToString());
Console.WriteLine((object)e.Value == (object)f.Value);
Console.WriteLine((object)e == (object)f);
Console.WriteLine(e == f);
Console.ReadLine();
}
}
}
</code>
try giving the output manually (i got it wrong )
And please explain your answer
|
|
|
|