|
Hi, I'm curious, why would a form need to catch keyboard events? What are you using it for? I can't think of any scenario where this can be used.
/Patric
My C# blog: C# Coach
|
|
|
|
|
Im building a small program which you can get the color of any pixel on the screen, color picker
after pointing on a pixel and getting its RGB and HEX into text boxes how would you remember them?
just clicking on a button will get them into a list of colors
|
|
|
|
|
Actually, they did. Form.KeyPreview[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How does one prototype an exported function call that has a HANDLE* parameter argument? I have tried "ref IntPtr" with no success.
Example:
C Prototype:
__declspec (dllexport) DWORD CALLTYPE func(HANDLE* phandle);
C# Prototype:
[DllImport("func.dll")]
static extern uint canOpen(ref IntPtr ptrHandle);
I get a "Invalid Handle" error from the OS when this is called.
TPF
|
|
|
|
|
Could the ref be causing the problem somehow? I'm using IntPtr's for handles while accessing user32.dll without issue.
|
|
|
|
|
T Finn wrote: ref IntPtr ptrHandle
Dont use ref . Else you are creating a pointer to a pointer.
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
What is confusing here is that the argument is a pointer to a IntPtr (HANDLE). Passing a IntPtr as a handle works but this function calles for passing a pointer to a handle (HANDLE*).
T Finn
|
|
|
|
|
T Finn wrote: IntPtr (HANDLE).
Since when? HANDLE is a struct, iow a valuetype.
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
After 22 years I am leaving AS/400 (shudder), dec unix, Linux, Java, openVms, MFC, C++, VB, Access, blah blah blah) to a new job that is pure C#/SQL.
After many years of being unmanaged , I am finally gonna get managed . ( I wish I could use VS C++ 2005 compiler for managed code, so I could manage the memory myself, sigh)
I have only done a few thousand lines of C# so here goes.
Pray for me.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
Good luck then. I came from an unmanaged background as well (though admittedly not as extensive as yours), and am loving C#.
Oh, by the way, if you've done Java, then you've done 'managed' code already.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
> I wish I could use VS C++ 2005 compiler for managed code, so I could manage the memory myself, sigh
Don't worry. With experience you will slowly begin appreciate the fact that the computer can manage memory better at runtime than you think can at compile time.
Matt Gerrans
|
|
|
|
|
I have a picturebox, which displays a bitmap.
I have coordinates, width, and height defined which correspond to a section of the image the picturebox displays.
I need to create a new image, from the section of the previous image that corresponds to my x,y,width,height variables.
Basically, I just need to extract the corresponding section of the image and create a new image from it.
Any ideas?
Thanks!
|
|
|
|
|
Assuming you have controls PictureBox1 and PictureBox2, and you want (for instance) a 50x50 pixel area of the image in PictureBox1 to appear in PictureBox2, then the following should work:
Image original = pictureBox1.Image;
Bitmap bmp = new Bitmap(50, 50);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(original, new Rectangle(0, 0 , 50 , 50), 50, 50, 50, 50, GraphicsUnit.Pixel);
pictureBox2.Image = (Image)bmp;
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Members,
I have a user control embedded on a single form. The form has a pubic method that I created. I want this child control to notify the parent page when new data is entered in to a text field on the user control. I want to keep the user control responsible for only the information that it is gathering. However, I want this parent page notified when new records are created.
How do I pass the record id as a string from the embedded control to the public function on the parent page?
Thanks for the thought...
SD
|
|
|
|
|
Raise a message in the control that the parent form handles.
|
|
|
|
|
You may ( for further use ) create an event on the usercontrol itself which may be this_DataChanged and it tracks all the changes that may have been done , and then in every parent you add this control in you just handle it.
ex:
public class MyControl : UserControl
{
public MyControl() { }
public event EventHandler DataAdded;
public DataType PropertyName
{
get { return dataField; }
set { this.dataField = value; this.OnDataAdded(); }
}
private void OnDataAdded(object sender, EventArgs e)
{
if (this.DataAdded != null)
{
this.DataAdded(this.DataAdded, e);
}
}
}
public class MyForm : Form
{
this.MyInheritedUserControl.DataAdded+=new EventHandler(this.MyEventHandler);
}
hope this helps.
"I am a liar." Is this statement true or false ?
|
|
|
|
|
LongHC,
Thank you very much for the solution.
Per you comment, it depends...In the land of Knights and Knaves, where Knights always tell the truth and Knaves always lie, you could not be a Knight and a Knave would never offer the truth--therefore, you must be a Paradox.
William
|
|
|
|
|
Hello, Everyone. I am just wandering, if anyone has ever tried adding a NumericUpDown control to a MenuItem. Any feedback would be greatly appreciated. Thank you very much in advance!
|
|
|
|
|
Can't figure this one out. I've got a picturebox on my form. In the designer it's visibility property is set to true. In code depending on inputs I want to either have it display an image, or be invisible (with other controls adjusting their layout to take it's place). When I traced into the setup method I found that on entry the property was false, and remainded so regardless of attempts to set it. All 3 lines of code below represent attempts to change the property. The first is what I had originally, the 2nd and 3rd were done just to see what would happen. In the latter case I was checking against the posibility that somehow the clr was !ing the parameter.
this.m_pbImage.Visible = true; //false before, false after
this.m_pbImage.Visible = !this.m_pbImage.Visible; //false before, false after
this.m_pbImage.Visible = false; //false before, false after
If I set the image property it will display despite visible being set to false immediately before calling show dialog. I could do the repositioning code where I'm currently setting the Visible property, but I'd rather only doso once in an if-else than in each of a halfdozen case values.
|
|
|
|
|
How to free the display of the form/control? SuspendLayout() can not work.
Thanks!
|
|
|
|
|
Inside my application is a window. Inside my window is a picturebox.
When my mouse is hovering above the picturebox, I need to know the coordinates, relative to that picturebox.
There is also a button on the side: "Define X,Y" -
If there user clicks that button, and the next click is on a point inside that picturebox, I need to record those coordinates.
Any idea how to go about this?
|
|
|
|
|
do you want to know the x,y inside the picbox?
Try:
<br />
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
label1.Text = "x=" + e.X.ToString() + " y=" + e.Y.ToString(); <br />
}<br />
Cheers,
Simon
> latest article :: animation mechanics in SVG
> blog:: brokenkeyboards
> another site of mine :: JeanPant.com
> CV :: PDF
|
|
|
|
|
Yeah. Just figured it out. Each object has its own mousemove event handler. All I had to do was set the mousemove handler for the picturebox alone. Thanks!
|
|
|
|
|
Hi All,
I am trying to host a foreign control ( may be a usercontrol or some other control
like a as tabcontrol ) as one of the columns of DataGridView.
As per my knowledge, I derived two classes:
DataGridViewUserControlColumn: DataGridViewColumn,
DataGridViewUserControlCell : DataGridViewCell
I have reached to a point where I can display the column on the DataGridView and each cell has a usercontrol. But when I scroll the DataGridView, the usercontrols
fail to scroll or change position. They remain where they are.
I am guessing that I haven't derived my two classes well ?
Any code sample will be of great help.
Below is my sample code that I was working around:
-----------------------------------------------------------------------------------------
using System;
using System.Windows.Forms;
public class CalendarColumn : DataGridViewColumn
{
public CalendarColumn()
: base()
{
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
// Ensure that the cell used for the template is a CalendarCell.
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CalendarCell)))
{
throw new InvalidCastException("Must be a CalendarCell");
}
base.CellTemplate = value;
}
}
}
public class CalendarCell : DataGridViewTextBoxCell
{
private Button btn = new Button();
private static int counter = 0;
private int thisButtonCount;
public CalendarCell()
: base()
{
// Use the short date format.
this.Style.Format = "d";
counter++;
thisButtonCount = counter;
this.btn.Text = thisButtonCount.ToString();
}
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
// Set the value of the editing control to the current cell value.
base.InitializeEditingControl(rowIndex, initialFormattedValue,
dataGridViewCellStyle);
CalendarEditingControl ctl =
DataGridView.EditingControl as CalendarEditingControl;
ctl.Value = (DateTime)this.Value;
}
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
//throw new Exception("The method or operation is not implemented.");
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
btn.Size = cellBounds.Size;
btn.Location = cellBounds.Location;
this.DataGridView.Controls.Add(btn);
}
public Button GetControl
{
get { return btn; }
}
public override Type EditType
{
get
{
// Return the type of the editing contol that CalendarCell uses.
return typeof(CalendarEditingControl);
}
}
public override Type ValueType
{
get
{
// Return the type of the value that CalendarCell contains.
return typeof(DateTime);
}
}
public override object DefaultNewRowValue
{
get
{
// Use the current date and time as the default value.
return DateTime.Now;
}
}
}
class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;
public CalendarEditingControl()
{
this.Format = DateTimePickerFormat.Short;
}
// Implements the IDataGridViewEditingControl.EditingControlFormattedValue
// property.
public object EditingControlFormattedValue
{
get
{
return this.Value.ToShortDateString();
}
set
{
String newValue = value as String;
if (newValue != null)
{
this.Value = DateTime.Parse(newValue);
}
}
}
// Implements the
// IDataGridViewEditingControl.GetEditingControlFormattedValue method.
public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}
// Implements the
// IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.
public void ApplyCellStyleToEditingControl(
DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.CalendarForeColor = dataGridViewCellStyle.ForeColor;
this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;
}
// Implements the IDataGridViewEditingControl.EditingControlRowIndex
// property.
public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}
// Implements the IDataGridViewEditingControl.EditingControlWantsInputKey
// method.
public bool EditingControlWantsInputKey(
Keys key, bool dataGridViewWantsInputKey)
{
// Let the DateTimePicker handle the keys listed.
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return false;
}
}
// Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit
// method.
public void PrepareEditingControlForEdit(bool selectAll)
{
// No preparation needs to be done.
}
// Implements the IDataGridViewEditingControl
// .RepositionEditingControlOnValueChange property.
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
// Implements the IDataGridViewEditingControl
// .EditingControlDataGridView property.
public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}
// Implements the IDataGridViewEditingControl
// .EditingControlValueChanged property.
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}
// Implements the IDataGridViewEditingControl
// .EditingPanelCursor property.
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}
protected override void OnValueChanged(EventArgs eventargs)
{
// Notify the DataGridView that the contents of the cell
// have changed.
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(eventargs);
}
}
public class Form1 : Form
{
private DataGridView dataGridView1 = new DataGridView();
[STAThreadAttribute()]
public static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.dataGridView1.Dock = DockStyle.Fill;
this.Controls.Add(this.dataGridView1);
this.Load += new EventHandler(Form1_Load);
//this.dataGridView1.CellFormatting +=new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
this.Text = "DataGridView calendar column demo";
this.dataGridView1.AllowUserToAddRows = false;
}
//public void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
//{
//}
private void Form1_Load(object sender, EventArgs e)
{
CalendarColumn col = new CalendarColumn();
CalendarCell cell = new CalendarCell();
col.CellTemplate = cell;
this.dataGridView1.Columns.Add(col);
this.dataGridView1.RowCount = 5;
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
row.Cells[0].Value = DateTime.Now;
}
}
}
----------------------------------------------------------------------------------------------
Below is the reference link for above code:
http://msdn2.microsoft.com/en-us/library/7tas5c80
Thanks..
Ritesh Tijoriwala
|
|
|
|
|
Could anyone help me out with a theoretical problem......
From my main thread I'm launching a child thread that each obtain a read lock from an instance of a ReaderWriterLock
If the child thread does not release the read lock before it expires, will the main thread inherit that read lock, enabling it to call UpgradeToWriterLock.
Sorry to be so vaugue if you need more details let me know.
Thanks,
Chris.
|
|
|
|
|