|
That would be a complete waste of memory and CPU cycles. The OnPaint virtual function and the event if fires - Paint - exist so that you can draw onto any control. Drawing into an images then assigning that images to a PictureBox is inefficient and requires much more memory than drawing on the control's surface itself. That can be done with a simple Panel as the poster is currently doing.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You can write any window to a DC using Windows API as it's being shown on the screen. You first need to call CreateDC("DISPLAY", null, null, null) and then use SendMessage to send a WM_PRINT to the window.
Alternatively, you'll need to rewrite your code and draw everything on the Panel's OnPaint.
Yes, even I am blogging now!
|
|
|
|
|
Extending on what Daniel said, you should rewrite your OnPaint to paint the entire surface (nodes and lines) but in a modular manner that you can pass a Graphics object (and perhaps the clip bounds) to paint on, but don't paint directly in OnPaint . This allows you to pass the Graphics for a PrintDocument (or even an HDC for some other device using Graphics.FromHdc ) and use the same drawing routines.
The common solution follows:
private void Paint(Graphics g, Rectangle bounds)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Paint(e.Graphics, Bounds);
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Paint(e.Graphics, e.PageBounds);
} Handling your mouse events isn't too hard if you design a nice abstract system of nodes where the Panel may translate mouse events to the nodes, but the nodes actually contain the code to move themselves. Polymorphism is a very powerful tool.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I want to do something when all the threads have been excuted,but I don't know how to detect this event.Can you tell me?
|
|
|
|
|
One very simple solution would be to create an array of bools that all the threads and your main process can see - each thread knows it's number (set by the main process when the thread starts) and when each thread finishes it sets it's relevant entry in the array to true.
Then the main process just needs to sporadically check the array, to see if they've all finished (and find out which thread it's waiting for)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Common solutions are:
1. Array of bools or a bool property on each thread controlling object (only if you need to know which threads are still running).
2. Static counter that gets incremented when each thread finishes.
3. Thread.Join each thread.
4. Use a synchronization object, e.g., an ManualResetEvent (my favorite).
Whatever solution you chose, don't forget to put robust exception handling, or your program will wait forever in case of an exception.
Yes, even I am blogging now!
|
|
|
|
|
Hi! I want to make NB shared folders scanner on C#.
How should I do this? Using netapi32.dll or perhaps, you could propose better choise??
PS: I'm sorry 4 my English$)
|
|
|
|
|
Start by enumerating the servers and workstations on the network using the NetServerEnum API exported by netapi32.dll. For each machine, enumerate its shares using the NetShareEnum API.
An example of using NetServerEnum can be found here[^].
See the Platform SDK for both NetServerEnum and NetShareEnum documentation at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How i can fire(run) an event on a DataGrid cell?
|
|
|
|
|
It depends on the type of cell...if it's just a normal text box, then you can handle the event on the textbox itself...
|
|
|
|
|
How do you get the CurrentCell's text box from the data grid?
Greg Bayard
|
|
|
|
|
I use DataGridTimePickerColumn(class in msdn) style DataGrid column, when I edit grid cell ,it work well ,but when i insert new row,it has error of data convert,how i do?
|
|
|
|
|
More than likely (since you didn't give any details about the exception being thrown to you) need to define a default value for the column that you use the DataGridTimePickerColumn class. The value it displays - a DateTime - is a value type and cannot be null. You could optionally check for DBNull.Value in your code (modify the example: it's only an example anyway) and either assign a default value then or handle it however you want.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot!
this my code
DataGridTimePickerColumn tpcsCreatedDate = new DataGridTimePickerColumn();
tpcsCreatedDate.MappingName = "CreatedDate";
tpcsCreatedDate.HeaderText = "CreatedDate";
tpcsCreatedDate.NullText = DateTime.Now.ToShortDateString();
myGridStyle.GridColumnStyles.Add(tpcsCreatedDate);
this is DataGridTimePickerColumn from msdn
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
// This example shows how to create your own column style that
// hosts a control, in this case, a DateTimePicker.
public class DataGridTimePickerColumn : DataGridColumnStyle
{
private DateTimePicker myDateTimePicker = new DateTimePicker();
// The isEditing field tracks whether or not the user is
// editing data with the hosted control.
private bool isEditing;
public DataGridTimePickerColumn() : base()
{
myDateTimePicker.Visible = false;
}
protected override void Abort(int rowNum)
{
isEditing = false;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
Invalidate();
}
protected override bool Commit
(CurrencyManager dataSource, int rowNum)
{
myDateTimePicker.Bounds = Rectangle.Empty;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
if (!isEditing)
return true;
isEditing = false;
try
{
DateTime value = myDateTimePicker.Value;
SetColumnValueAtRow(dataSource, rowNum, value);
}
catch (Exception)
{
Abort(rowNum);
return false;
}
Invalidate();
return true;
}
protected override void Edit(
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible)
{
DateTime value = (DateTime)
GetColumnValueAtRow(source, rowNum);
if (cellIsVisible)
{
myDateTimePicker.Bounds = new Rectangle
(bounds.X + 2, bounds.Y + 2,
bounds.Width - 4, bounds.Height - 4);
myDateTimePicker.Value = value;
myDateTimePicker.Visible = true;
myDateTimePicker.ValueChanged +=
new EventHandler(TimePickerValueChanged);
}
else
{
myDateTimePicker.Value = value;
myDateTimePicker.Visible = false;
}
if (myDateTimePicker.Visible)
DataGridTableStyle.DataGrid.Invalidate(bounds);
}
protected override Size GetPreferredSize(
Graphics g,
object value)
{
return new Size(100, myDateTimePicker.PreferredHeight + 4);
}
protected override int GetMinimumHeight()
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override int GetPreferredHeight(Graphics g,
object value)
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override void Paint(Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum)
{
Paint(g, bounds, source, rowNum, false);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
bool alignToRight)
{
Paint(
g,bounds,
source,
rowNum,
Brushes.Red,
Brushes.Blue,
alignToRight);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
DateTime date = (DateTime)
GetColumnValueAtRow(source, rowNum);
Rectangle rect = bounds;
g.FillRectangle(backBrush,rect);
rect.Offset(0, 2);
rect.Height -= 2;
g.DrawString(date.ToString("d"),
this.DataGridTableStyle.DataGrid.Font,
foreBrush, rect);
}
protected override void SetDataGridInColumn(DataGrid value)
{
base.SetDataGridInColumn(value);
if (myDateTimePicker.Parent != null)
{
myDateTimePicker.Parent.Controls.Remove
(myDateTimePicker);
}
if (value != null)
{
value.Controls.Add(myDateTimePicker);
}
}
private void TimePickerValueChanged(object sender, EventArgs e)
{
this.isEditing = true;
base.ColumnStartedEditing(myDateTimePicker);
}
}
please give me some more help!
|
|
|
|
|
I invoked the format command of OS(XP) in my code.But evry time it display a console window and I have to click the Enter key to go on the function. So,I wonder if there is a way to perform carriage return automatically and we do not need to click the Enter key?
Thanks for help!
|
|
|
|
|
|
Have you tried?
echo. | format a:
I don't know if it'll work, but give it a try. It's old DOS redirection, you are redirecting the ouput of the ECHO command (a carraige return) to the input of the FORMAT command.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi,
Sometimes the datagrid control is updating very slowly for some reason. In my program i have these circle objects and whenever the user clicks on one, the following occurs:
1. I create new DataRows for information contained in the circle clicked.
2. The rows are added to the DataTable bounded by the DataGrid.
3. When a different circle is clicked, the DataTable clears and the following steps are repeated.
The delay only seems to occur when a circle is clicked for the first time, each initial circle clicked on seems to update without a hitch.
Is this a cache issue? Thanks for the help!
Brian
|
|
|
|
|
Hello!
I´m new to C# and have a question for the pro's.
Is it possible to put an ArrayList into another ArrayList like a 2d array?
How would the code look like?
Regards.
stumpi
|
|
|
|
|
ArrayList list1 = new ArrayList();
ArrayList list2;
for (int i=0; i< 2 ;++i)
{
list2 = new ArrayList();
list2.Add(i);
list1.Add(list2);
}
|
|
|
|
|
Not sure if this is a stupid problem.
I have a C# ASP.NET app that is consuming web services from third party product.
Problem is this third party prog is using some odd formats for passing back certain types.
Examples
A bool value will return either “true” or <null>
A date/time stamp will have the letter “T” inserted in the string before the time component.
.NET’s default SOAP interpretation is having problem with these types and the third party product is kind of a black box.
Sticking in an override for handling of these types at the .NET end would be ideal, but I’m kind of shooting blind on where to start.
Has anyone run across an issue like this before?
WR
|
|
|
|
|
Have a look around the net/CodeProject/MSDN for information on SOAP Extensions. These allow you to do various things with SOAP packets before and after serialization and deserialization.
If you have, or can lay hands on "Developing XML Web Services and Server Components with Visual Basic .NET and Visual C# .NET" (ISBN 0-7356-1586-1) they are explained on page 446.
Failing that use these keywords:
AfterDeserialize
AfterSerialize
BeforeDeserialize
BeforeSerialize
SoapExtension
I realize this is only a push in the right direction, but it is a large-ish topic.
Cheers, Steve
|
|
|
|
|
How can i get all the relavant info from an MP3 file using C#?
like the ID3 tag and the other MPEG info?
And also how can i edit it?
VisionTec
|
|
|
|
|
This is not perfect but it works.
<br />
<br />
namespace id3 {<br />
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
<br />
class FileCommands <br />
{<br />
<br />
public static void GetMP3Tag (ref MP3 paramMP3) <br />
{<br />
try<br />
{<br />
FileStream oFileStream;<br />
oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
byte[] bBuffer = new byte[128];<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
oFileStream.Read(bBuffer,0, 128);<br />
oFileStream.Close();<br />
<br />
Encoding instEncoding = new ASCIIEncoding();
string id3Tag = instEncoding.GetString(bBuffer);<br />
<br />
<br />
<br />
if (id3Tag .Substring(0,3) == "TAG") <br />
{<br />
paramMP3.id3Title = id3Tag.Substring( 3, 30).Trim();<br />
paramMP3.id3Artist = id3Tag.Substring( 33, 30).Trim();<br />
paramMP3.id3Album = id3Tag.Substring( 63, 30).Trim();<br />
paramMP3.id3Year = id3Tag.Substring( 93, 4).Trim();<br />
paramMP3.id3Comment = id3Tag.Substring( 97,28).Trim();<br />
<br />
<br />
<br />
if (id3Tag[125]==0)<br />
paramMP3.id3TrackNumber = bBuffer[126];<br />
else<br />
paramMP3.id3TrackNumber = 0;<br />
<br />
paramMP3.id3Genre = bBuffer[127];<br />
paramMP3.hasID3Tag = true;<br />
}<br />
else <br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
catch<br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
<br />
public static void UpdateMP3Tag (ref MP3 paramMP3) {<br />
paramMP3.id3Title = paramMP3.id3Title.Trim();<br />
paramMP3.id3Artist = paramMP3.id3Artist.Trim();<br />
paramMP3.id3Album = paramMP3.id3Album.Trim();<br />
paramMP3.id3Year = paramMP3.id3Year.Trim();<br />
paramMP3.id3Comment = paramMP3.id3Comment.Trim();<br />
<br />
if (paramMP3.id3Title.Length > 30) paramMP3.id3Title = paramMP3.id3Title.Substring(0,30);<br />
if (paramMP3.id3Artist.Length > 30) paramMP3.id3Artist = paramMP3.id3Artist.Substring(0,30);<br />
if (paramMP3.id3Album.Length > 30) paramMP3.id3Album = paramMP3.id3Album.Substring(0,30);<br />
if (paramMP3.id3Year.Length > 4) paramMP3.id3Year = paramMP3.id3Year.Substring(0,4);<br />
if (paramMP3.id3Comment.Length > 28) paramMP3.id3Comment = paramMP3.id3Comment.Substring(0,28);<br />
<br />
byte[] tagByteArray = new byte[128];<br />
for ( int i = 0; i < tagByteArray.Length; i++ ) tagByteArray[i] = 0;
<br />
Encoding instEncoding = new ASCIIEncoding();
byte[] workingByteArray = instEncoding.GetBytes("TAG"); <br />
Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Title);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Artist);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Album);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Year);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Comment);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);<br />
tagByteArray[126] = paramMP3.id3TrackNumber;<br />
tagByteArray[127] = paramMP3.id3Genre;<br />
<br />
FileStream oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
if (paramMP3.hasID3Tag)<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
else<br />
oFileStream.Seek(0, SeekOrigin.End);<br />
oFileStream.Write(tagByteArray,0, 128);<br />
oFileStream.Close();<br />
paramMP3.hasID3Tag = true;<br />
}<br />
<br />
}<br />
<br />
struct MP3 <br />
{<br />
public string filePath;<br />
public string fileFileName;<br />
public string fileComplete;<br />
public bool hasID3Tag;<br />
public string id3Title;<br />
public string id3Artist;<br />
public string id3Album;<br />
public string id3Year;<br />
public string id3Comment;<br />
public byte id3TrackNumber;<br />
public byte id3Genre;<br />
<br />
public override string ToString()<br />
{<br />
return id3Title;<br />
}<br />
public MP3(string path, string name) <br />
{<br />
this.filePath = path;<br />
this.fileFileName = name;<br />
this.fileComplete = path + "\\" + name;<br />
this.hasID3Tag = false;<br />
this.id3Title = null;<br />
this.id3Artist = null;<br />
this.id3Album = null;<br />
this.id3Year = null;<br />
this.id3Comment = null;<br />
this.id3TrackNumber = 0;<br />
this.id3Genre = 0;<br />
}<br />
} <br />
}<br />
<br />
<br />
Leon v Wyk
|
|
|
|
|
This is a purely theoretical question--I'm not even asking for help this time.
I've been working a bunch with some clever datastructures and I have found myself needing to provide Equals overrides so that when I use Contains a correct comparison is used to determine whether elements are inside a datastructure.
Anyway, when you override Equals, you have to override GetHashCode. Why exactly is this? Is it that the default Equals behavior involves comparison of hash numbers for the objects being compared? I always thought that the default Equals was just comparison of addresses. Maybe it's my java experience bubbling over.
On this topic, if we do not know exactly how Microsoft/.NET's default implementation of GetHashCode operates, when we write our own implementations of GetHashCode isn't it possible that we could... well... really muck things up? It just seems like we would want the same hashing behavior for ANY kind of object.
vir·tu·al re·al·i·ty
n. Abbr. VR
A computer simulation of a real or imaginary universe in which Microsoft APIs are thoroughly documented and behave in an entirely logical manner.
|
|
|
|
|