|
Thanks lisan_al_ghaib
but i try this, before post, this code :
private void AddControlToMyEventHandler
{
if (control is DataGridView) (control as DataGridView).CellValueChanged += new EventHandler(this.OnControlValueChanged);
}
couse the following error message shown me :
Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.Forms.DataGridViewCellEventHandler'
|
|
|
|
|
hdv212 wrote: Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.Forms.DataGridViewCellEventHandler'
That is pretty self explanatory. Your event hooking should be
(control as DataGridView).CellValueChanged += new DataGridViewCellEventHandler(this.OnControlValueChanged);
|
|
|
|
|
Thanks N a v a n e e t h
This code work, but my problem was not solved, i need to cast my event handler to another event without create new event handler, in other word, i want cast current eventHandler (this.OnControlValueChanged) and pass it to DataGridView.CellValueChanged eventHandler.
thanks
|
|
|
|
|
Hi,
I'm a rather new C# user and I'm still figuring out the ropes of forms programming and such.
For the part of the program I'm working on, I basically want to move an image around on the screen, in a region (advanced, I know <end sarcasm="">). I achieved this just fine with mouse click and drag, but I'm unable to get any sort of keyboard input. Here's the part of the code I'm using:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
using(Region boardRegion = new Region(new Rectangle(ClientRectangle.X, ClientRectangle.Y,
(int)(ClientRectangle.Width), (int)(ClientRectangle.Height * boardRegionSize))))
{
g.Clip = boardRegion;
using(Bitmap boardImage = new Bitmap(board.ImagePath)){
g.DrawImage(boardImage, board.X, board.Y);
}
}
base.OnPaint(e);
}
private void CMGame_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
board.Y -= 30;
}
And for part of InitializeComponent(), I have
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CMGame_KeyDown);
(automatically done by windows)
Basically, nothing happens when I press a key (the up arrow or anything else, since I've tried different keys in testing)
I read somewhere that I could try overriding WndProc, but I don't know how I would do this (even after I wrote the override method header and and found the code for KeyDown, 0x0100)
For reference, I also have a button in the form with a click event.
Help would be much appreciated.
|
|
|
|
|
You need to tell the control that's holding the image that is needs to be redrawn either by calling it's invalidated method or calling onpaint directly depending on the situation. You could hook this up to be done automatically by putting it in a locationchanged event which you can fire whenever X or Y is changed
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Right, I actually had that earlier before I started messing with things. Even with this.Invalidate() after it, nothing happens. I think that the event isn't being fired at all, since, for parts of my test, I just told the keydown, keypress, and keyup to change the text of the form. Nothing happened anytime I pressed a button.
|
|
|
|
|
Ok, I found my problem. Once I removed my button, the key input worked again. Can anyone tell me what else would have worked?
modified on Sunday, August 17, 2008 7:36 PM
|
|
|
|
|
Is it a focus problem? Was the button getting the keyboard input? If so, setting the form's KeyPreview property to true might be the solution.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Thanks, setting the KeyPreview to true worked perfectly for me.
|
|
|
|
|
Hola!
Here's a short description of my what I wanna do:
I'll create a program which is running all the time
I've got the computer on and it will listen to my typing,
and if I type a certain word, let's say "calculator" the
program will start the calculator up.
My problem is that I have no idea of how to get started with
the keylistening.. Ofcourse it needs to work while out of focus
too.. I need a push in the right direction - anyone?
/Joplinazz
|
|
|
|
|
search here and google for keyboard hooks
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
|
Hi
i define this interface :
public interface Interface1
{
void myMethod();
}
then create class which inherited from our interface :
public class Class1 : Interface1
{
#region Interface1 Members
private void myMethod()
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
as you can see in second code, i set modifier of myMethod to private, but the following error message has shown me :
'WindowsApplication10.Class1' does not implement interface member 'WindowsApplication10.Interface1.myMethod()'. 'WindowsApplication10.Class1.myMethod()' is either static, not public, or has the wrong return type.
i want to set it's modifier to private to prevent access to this method outside of my class, but how to do ?
thanks
|
|
|
|
|
This doesn't quite make sense. Interfaces are used to quarantee existence of methods, properties, indexers or events that are public. For this reason implementation must be public.
If you don't want the method to be callable outside of your class, don't put it in an interface.
Mika
|
|
|
|
|
Mika is correct, it doesn't make sense to declare interface method implementations as private , that's not what they're for.
You can however use an abstract class like this:
public abstract class Vehicle
{
abstract protected void SomeMethod();
}
public class Car : Vehicle
{
protected override void SomeMethod()
{
throw new NotImplementedException();
}
}
However, the lowest access level is protected in this case.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you implement it Explicitly
void Interface1.MyMethod()
{
throw new NotImplementedException();
} then it will remain invisible unless a Class1 instance is explicitly cast to Interface1 like
Class1 class1 = new Class1();
Interface1 interface1 = (Interface1)class1;
interface1.MyMethod();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
That's true, however then this sort of defeats the purpose of an interface, because often you just do something like
IInterface obj = Factory.GetSomeImplementation();
Usually you don't access (and don't care about) the direct implementation for an instance.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I totally agree - just trying to give the OP an alternative that may work in his situation.
A better way may be to have a base interface without the method that he could use and a second interface that inherits from the first for when he needs the method
public interface Interface1
{
}
public interface Interface2 : Interface1
{
void myMethod();
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
If you don't want your method to be public or accessible via the interface (explicit impl) then the solution is very simple:
remove the interface from your class since you are not using the class through that interface..
|
|
|
|
|
I am setting the image in a treeview by:
oNode = treeview1.Nodes.Add(sCaption);
oNode.Tag = sTagValue;
oNode.ImageKey = sImageKey;
oNode.Expand();
The images are being set fine. But when I click on a node, the icon changes to the icon set on the root node. When I click a different node, the prior node's image changes back to its correct icon.
Anyone know what I'm doing wrong?
Everything Makes Sense In Someones Mind
|
|
|
|
|
Check SelecteImageKey for the node. ImageKey is used only when node is not selected.
Mika
|
|
|
|
|
Hello everyone..
Im writing a c# app that needs to be able to receive notifications that have been sent by a web app using asp.net.
the notification can be sent to the inbox or directly to the desktop app if thats possible.
if its sent to the email, the app needs to somehow flag that an email has been received in the inbox. if they are sent directly to the desktop app it also needs to flag and the email be opened in the app.
please help...!!!
|
|
|
|
|
Do you even have the slightest idea about what kind of security issues what you are asking for can bring? You do not want a web application controlling the desktop or client machine.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there.
I saw somewhere that obj1.Equals(obj2) is faster than obj1==obj2
Is it true ?
|
|
|
|
|
Mohammad Dayyan wrote: I saw somewhere that obj1.Equals(obj2) is faster than obj1==obj2
Leave alone the fast execution part but do you know that these two statements may not give the same result always.
Well, my personal suggestion is before posting the questions in the forum, atleast try to have a look at msdn. There are many chances that you will get the answer there itself.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|