|
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.
|
|
|
|
|
Does anyone know how to force the xmlDataDocument to include elements for nulls (from the dataTable in the dataSet) in the resulting xml?
I'm transforming the xml into an html table and without all the elements the columns are misaligned.
|
|
|
|
|
|
|
HI,
I have a requirment where in I have to show a child form without
losing the focus of the invoking form/mdi form.
My application shows a Popup window rising from the task bar.
This popup form is invoked by the main MDI form which handles
several events from the server. Based on the event type I create
an instance of the popup form and show the Popup form. During this
period the MDI form loses its focus. Once the Popup goes down, the
MDI form regains focus.
I have used ShowWindow(this.Handle, 4) API call which in turn is supposed to open
a form without focus.
But still this does not work.
Is there anybody who can suggest me the solution for this problem.
Any help/suggestion is hightly appreciated.
Regards,
Hitesh
hiteshsalian@yahoo.co.in
|
|
|
|
|
Hi,
I am having a similar problem. Have you found solution for this? If so, Please let me know...
Thanks
Muthu.
|
|
|
|
|
Can anybody tell me how can i determine the number of drives and drive letters in my system in C#? And also the size of each drive...
|
|
|
|
|
DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
Each DriveInfo object will have TotalFreeSpace and a TotalSize property.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Environment.GetLogicalDrives()
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!
|
|
|
|
|
I have just read Jeffrey Richter's article: "Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework",I have a question about finalize.It says "A finalizable object can refer to other(finalizable and nonfinalizable) objects, prolonging their lifetime unnecessarily.".It also says "The runtime doesn't make any guarantees as to the order in which Finalize methods are called. For example, let's say there is an object that contains a pointer to an inner object. The garbage collector has detected that both objects are garbage.Furthermore, say that the inner object's Finalize method gets called first." I am confused the outer object's finalize method doesn't get called,so the inner object is reference by the outer object.Why does the garbage collector think that the inner ojbect is garbage.I notice the former uses refer and the latter used a pointer.Is this reason,otherwise why?
|
|
|
|
|
It's a two-pass process, first establishing what is garbage, then secondly collecting it.
When garbage collection kicks in, the CLR determines what is and what is not garbage by following object references from initial 'live' roots to one object to the next. All objects are considered garbage unless they are marked otherwise by this process. If the inner object is only referenced by the outer object, and the outer object never gets marked as 'live', then both objects are considered garbage.
The GC will then go on to collect them and you can't make any assumptions about in which order (I believe its in the order they are in memory).
Are you assuming that objects are deleted in Finalize in a similar manner to the general practice in a C++ destructor? This is not the case. My understanding is that Finalize is provided more to free up CLR resources than referenced objects.
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: Are you assuming that objects are deleted in Finalize in a similar manner to the general practice in a C++ destructor? This is not the case. My understanding is that Finalize is provided more to free up CLR resources than referenced objects.
You've got this part backwards. Finalize() is to cleanup non managed (and generally scarce) resources (ie handles, files) that the GC can't. If you've implemented a finalizer you should also should implement IDisposable, and dispose the object as soon as you're done (put the cleanup code in both) to free the nonmanaged resources immediately rather than waiting for the GC. The reason for doing the cleanup in both places is cya in case you or annother developer forget to dispose the object.
|
|
|
|
|
Hey
I'm looking for a list with all the "\" signals for strings.
I do know that \n is start another line, and \t is for tabbing,
but what \r is doing, and what other signs exist.
thanks!
|
|
|
|
|
Copied from MSDN Library:
Escaped character Description
\a
Matches a bell (alarm) \u0007.
\b
Matches a backspace \u0008
\t
Matches a tab \u0009.
\r
Matches a carriage return \u000D.
\v
Matches a vertical tab \u000B.
\f
Matches a form feed \u000C.
\n
Matches a new line \u000A.
\e
Matches an escape \u001B.
\040
Matches an ASCII character as octal (up to three digits); numbers with no leading zero are backreferences if they have only one digit or if they correspond to a capturing group number. (For more information, see Backreferences.) For example, the character \040 represents a space.
\x20
Matches an ASCII character using hexadecimal representation (exactly two digits).
\cC
Matches an ASCII control character; for example, \cC is control-C.
\u0020
Matches a Unicode character using hexadecimal representation (exactly four digits).
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This seems to be copied from the documentation about regular expressions, not the C# documentation.
The escapes are quite similar, though.
|
|
|
|
|
You're right, that's the first one I found. But as you said they're pretty much the same.
I just removed some of the regex-specific stuff from my original posting to not to confuse him.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Hi:
What is involved in setting up a serial port (RS232) under .NET and specifically, using C#?
Does C# offer anything that supports this or do I have to drag some Win32 DLL into it?
There is an example on this site but it uses a SerialPort class that is supposed to be part of the "System.IO" name space. I'm using Visual Studio 2003. I can't find that in any of my documentation.
I specifically need to set up asynchronous communication so I need a background thread to service incoming characters.
Thanks in advance to anybody who responds.
Cheers,
Mark
|
|
|
|
|
This link might shed some light on the matter -
http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx
|
|
|
|
|
Thanks Gavin. This looks exactly like what I am looking for.
Cheers,
Mark
|
|
|
|
|