|
Thanks a lot. It worked
|
|
|
|
|
I am trying to detect KeyDown to detect "CTL+A" with following code:
Form1.KeyDown += new KeyEventHandler(OnKeyPress);
public void OnKeyPress(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.A && e.Control)
MessageBox.Show("CTL+A was pressed");
else
{
MessageBox.Show("Wrong Key pressed");
}
}
Still does not work. it does not like this line
Form1.KeyDown += new KeyEventHandler(OnKeyPress);
ANy help is greatly appreciated.
|
|
|
|
|
|
I made the changes
*************
public void OnKeyPress(object sender, KeyEventArgs e)
{
if(e.KeyCode == (Keys.A | Keys.Control))
MessageBox.Show("CTL+A was pressed");
else
{
MessageBox.Show("Wrong Key pressed");
}
}
*****************************
but still does not work, I think is because I am not trapping the KeyDown handler correctly
|
|
|
|
|
Does some other control have the focus when you press it?
It seems to me the best way to go about doing this is to override the ProcessCmdKey method and listen from there. That way you'll catch the key press no matter which control has focus.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
When I run the application, one of the textBox has the focus. Is there a way to give the current Form the focus? or do you have a sample code to override using ProcessCmdKey?
Thanx in advanced
|
|
|
|
|
picasso2 wrote: When I run the application, one of the textBox has the focus.
That explains why the form's key press handler isn't catching the key; the key was pressed for the text box, not the form.
picasso2 wrote: do you have a sample code to override using ProcessCmdKey?
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.A))
{
MessageBox.Show("You pressed CTRL+A!");
}
return base.ProcessCmdKey(ref msg, keyData);
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
You can use Form.KeyPreview and Form.KeyDown:
MyForm.KeyPreview = true;
MyForm.KeyDown += new KeyEventHandler(MyForm_KeyDown);
.
.
.
private void MyForm_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.A) && e.Control && !e.Alt)
{
Debug.WriteLine("Ctrl + A");
}
}
-- modified at 2:44 Sunday 9th July, 2006
|
|
|
|
|
Keyboard handling is one of the most confusing thing in the Control class.
To know it all in great detail read that:
.. uh.. can't find the article again.
to make it simple override ProcessDialogKey
|
|
|
|
|
Hey all. I am currently using a low level mousehook to retrieve the mouse position. I would like to know if there is a function in .NET 1.1 that will allow me to retrieve the mouse coordinates when a Form is created or the program starts. I don't think I can use mouse events unless I can programatically call an event (such as mouse move). I am new to C# so any help would be greatly appreciated.
Thanks!
Josh
|
|
|
|
|
Josh, you can use Cursor.Position to determine the position of the mouse at any time. You don't need to handle an event in order to query this property.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
ahh right, the static instance of Cursor. I also found that Control.MousePosition works as well. Thanks for the help.
|
|
|
|
|
I'm looking for an idea how to draw image to looks like semi-transparent. The image will be generated with code, so I can't make it directly semi transparent. I need this to be fast, can't make it pixel by pixel.
Thanks in advance
|
|
|
|
|
alexiev_nikolay wrote: The image will be generated with code, so I can't make it directly semi transparent.
Why is that?
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I've done that in one of my articles. The following code applies an alpha value to a bitmap:
private unsafe void ApplyAlphaToImage(Bitmap image)
{
if (image == null || _alpha == 255)
return;
int imageWidth = image.Width;
int imageHeight = image.Height;
BitmapData data = null;
try
{
data = image.LockBits(new Rectangle(0, 0, imageWidth, imageHeight),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int scan0 = data.Scan0.ToInt32();
int stride = data.Stride;
byte * colPixel;
byte invertedAlpha = (byte)(255 - _alpha);
byte * rowPixel = (byte *)scan0;
for (int y = 0; y < imageHeight; y++)
{
colPixel = rowPixel + 3;
for (int x = 0; x < imageWidth; x++)
{
if (*(colPixel) < invertedAlpha)
*(colPixel) = 0;
else
*(colPixel) = (byte)(*(colPixel) - invertedAlpha);
colPixel += 4;
}
rowPixel += stride;
}
}
finally
{
if (data != null)
image.UnlockBits(data);
}
}
This is still pixel by pixel but not using the regular Get/SetPixel functions but LockBits unsafe code. It is relatively fast - fast enough at least so I could use it in animations. Look here[^] to see the results.
|
|
|
|
|
i have a question which was asked before on this site, but apparently has never been answered propperly:
What if i want to scan the memory of a process to find some variables ? For instance i want to create a game trainer like ArtMoney. I introduce a value, and the program finds all the locations in the process' memory which mach my value.
My question is simple: where do i start the search, and where do i stop. I already tried the dummest thing, which was to scan from 0x00000000 and until i find my value... Obviously it got blocked at some point, before finding my value...
I was thinking that most likely, every process has to have a unique address where it memorizes the variables... But i don't know and i can't seem to find anything about that on the net...
Please help. Or at least guide me to an article solving my problem.
Thanks
bunny EATING rabbit
|
|
|
|
|
WinDbg will show u the memory addresses.
|
|
|
|
|
how to drag and drop a file to my form? and how to get the property of selected file(files)?
thanks for help.
erfan
|
|
|
|
|
Set the AllowDrop property to true and handle the DragEnter and DragDrop events.
In the DragEnter event, you'll have to set the Effect property of the DragEventArgs to something else but None , otherwise the DragDrop event will not be called.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
|
I'm makign a web browser, how do you make the status bar load in sync with the website?I've even downlaoded source codes for other browser tutorials but they never work.
-- modified at 14:30 Saturday 8th July, 2006
|
|
|
|
|
Use the navigating and documentcompleted events if you want to know when the browser starts and finishes navigating.
Alternatively, if you want to know how much has been downloaded and how much needs to be downloaded of the webpage, use the e.CurrentProgress and e.MaximumProgress properties of the progresschanged event of the webbrowser.
|
|
|
|
|
Hi All,
I am using combobox i filled combobox and noe I want to access combobox values.
my code is
comboBox1.DataSource =_orderBO.FillCombo("select CustomerId from Customers");
comboBox1.DisplayMember="CustomerId";
comboBox1.ValueMember="CustomerId";
MessageBox.Show ("Item is"+ comboBox1.Items[1].ToString());
Gives value "system.data.datarowview" as messagebox
Please help me....
-- modified at 9:29 Saturday 8th July, 2006
|
|
|
|
|
That is what you get when you use the ToString method on a DataRowView object.
Cast the item to DataRowView, then you can get the data you want from it.
---
b { font-weight: normal; }
|
|
|
|
|
SqlConnection conn= new SqlConnection("urconnectionstrng");<br />
DataSet dst = new DataSet();<br />
SqlDatAdapter dap = new SqlDataAdapter("select CustomerId from Customers",conn);<br />
comboBox1.DataSource =dst.Tables[0];<br />
comboBox1.DisplayMember="CustomerId"; <br />
comboBox1.ValueMember="CustomerId"; <br />
<br />
MessageBox.Show ("Item is"+ comboBox1.Items[1].ToString());
|
|
|
|