|
Thanks Luc!
I agree that just because some class is managed, doesn't mean that it will not call unmanaged code. (Good point)
You've definitely cleared up some question marks in my brain!
The hurrier I go, the behinder I get.
|
|
|
|
|
Richard Blythe wrote: what about un-wiring event handlers from a class before it's reference is set to null? I've code that removes handlers and code that doesn't.
AFAIK, you don't have to unwire each event. Setting it to null will remove the invocation list.
|
|
|
|
|
However, if consumer1 and consumer2 both wire to some event in producer3, and only consumer1 wants to exit the game, then noone is allowed to set the event to null since that would break the producer3-consumer2 relation.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Yeah. That's right
|
|
|
|
|
As far as I'm concerned, the definitive article on finalizers and disposable objects can be found over on Joe Duffy's Blog[^].
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I absolutely disagree with the "Dispose(bool)" pattern.
It's verbose and hard to use correctly. And it's only really useful when a class contains both managed and unmanaged resources, and there might even be derived classes that have their own unmanaged resources.
The solution is simple: don't do that.
Instead, create a sealed class for each unmanaged resource (bonus points if its derived from SafeHandle). Then your other classes only have to deal with managed resources, so they never need a finalizer and the Dispose method is trivial (just call Dispose on all members).
For more details, take a look at Stephen Cleary's article 'IDisposable: What Your Mother Never Told You About Resource Deallocation'[^].
|
|
|
|
|
I am attempting to do a custom OnPaint on a custom Treeview with a lot of bumps along the way. At this point in the game, I'm just trying to get a purple rectangle to print out anywhere involving this TreeView. I'll work on the bounds afterwards.
I found out the long way that WndProc turns off OnPaint and am trying to now to override WndProc, but I have absolutely no idea what to pass to OnPaint seeing this is my first attempt at GDI and from all the examples I've been looking at OnPaint appears to be called implicitly by other Win Forms. Please point me in the right direction.
public class myProfileTree : System.Windows.Forms.TreeView
{
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush brush = new SolidBrush(Color.MediumOrchid);
Rectangle blueRectangle = new Rectangle(50, 50, 200, 100);
g.FillRectangle(brush, blueRectangle);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case(15):
{
OnPaint( );
break;
}
default:
{
break;
}
}
base.WndProc(ref m);
}
}
|
|
|
|
|
As obvious as it seems, have you set the DrawMode to: TreeViewDrawMode.OwnerDrawAll?
The hurrier I go, the behinder I get.
|
|
|
|
|
Not entirely sure that is the direction I want to be taking. This just appears to erase my entire custom treeview with no call to OnPaint.
I'm trying to keep the way the rest of the nodes aside from a selected node to look the norm. I need to keep the selected node the focus color as buttons are pressed even though this goes against standard convention. The thought was to make a custom treeview with custom onpaint to repaint this one node with a rectangle using onpaint and then putting back the original text on top.
Then I read this: http://www.codeproject.com/Messages/685886/Re-Custom-Tree-View-Painting.aspx and came to the overriding WndProc, but was unsure on how to procede with the call to OnPaint.
|
|
|
|
|
I need to keep the selected node the focus color
If that's all your after then set the: "HideSelection" property to false. This setting allows you to retain visibility of the selected node once the treeview has lost focus.
If you still want your own paint, just manualy set the node's properties:
tv.SelectedNode.BackColor = SystemColors.Highlight;
...
The hurrier I go, the behinder I get.
|
|
|
|
|
HideSelection will not work for this instance and changing the BackColor will not address the issue I have. My button moves the selected node up and down. Since it is no longer the focus, it turns from medium blue to light gray. I did however figure out how to override WndProc:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case (15):
{
PaintEventArgs pae = new PaintEventArgs(
Graphics.FromHwnd((m.HWnd)),
new Rectangle(0, 0, this.Width, this.Height));
OnPaint(pae);
break;
}
default:
{
break;
}
}
}
Thanks for trying!
|
|
|
|
|
Hi All,
I am working on a c# tool to copy part of excel rows to another excel sheet.
i.e i want to copy row 5 to row 10 in Excel1 and create a new exce2.
any sample code will be helpfull.
Regards,
Kasi
|
|
|
|
|
Well, there are a couple of options.
You can use Office Interops to read the excel file and then create the second with the data of your interest.
Another way can be to read the excel sheet using the ADO connection into a dataset and you can write the selected rows as a xml file (using Dataset.writeTo method). Excel can easily read the xml file.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi,
Thanks for your quick reply. Can you send me some sample code.
Regards,
Kasi
|
|
|
|
|
What have you tried already? Have you researched how to do read and write from excel files? Many people don't like doing work for free, and 'sample' code exists on the internet everywhere, if you have tried using google that is.
|
|
|
|
|
Thanks, I got some code on google.
|
|
|
|
|
Hi guys.
Can we send email in C# (WinForm) with our free YahooMail or Gmail account ?
Thanks.
|
|
|
|
|
Did you try this[^] before posting your question?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you.
I've found the answer.
try
{
NetworkCredential loginInfo = new NetworkCredential("username", "password");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("something@gmail.com");
msg.To.Add(new MailAddress("sth@sth.com"));
msg.Subject = "Email Subject";
msg.Body = "Some text";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
MessageBox.Show("Your password has sended to your email", "Email sended", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|
Hi Guys,
I have the following out put from Sql data adapter(sda)
WebRequest req = null;
WebResponse rsp = null;
Dataset ds=new dataset();
Sda.fill(ds)
string xmlDs= ds.Getxml();
string fileName = xmlDs;
string uri = "http://www.webpage/default.appx";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml";
I would like to Encript the Xml data before sending it accross.How would i go about it?
Thank you in advance.
|
|
|
|
|
The Cryptography namespace is where you need to go. Thing is, do you want to encrypt the XML ( which will mean it's not XML anymore ), or some of the data IN the XML ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi All,
i have a code (below), it take 2 variables, the first being the server name and the second being the eventID to look for in the Directory Service eventlog.
it seems to work fine for all eventID's except the one im looking for - 1394, where it always shows nothing!!
any ideas?
EventLog el = new EventLog("Directory Service", args[0].ToString());
foreach(EventLogEntry i in el.Entries)
{
if(Convert.ToInt32(i.EventID) == Convert.ToInt32(args[1]))
{
Console.WriteLine(i.EventID.ToString() + " - " + i.TimeWritten.ToShortDateString());
}
}
|
|
|
|
|
lane0p2 wrote: it seems to work fine for all eventID's except the one im looking for - 1394, where it always shows nothing!!
Probably, there is no event for this id
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
there is!!
i was looking at the eventviewer and ended up testing loads of ID but only 1394 failed.
i just can't figure it out!
|
|
|
|
|
Hey buddys...........I was trying to use an animated picture pox which acts as a button in my application...................So what I wanted was,when the user mouseEnter in to this picture box i wanted to show another picture box which is the same as that picture but the brightness is more than the previous picture box.................I done it easly by going to photoshop and adding a brightness on the picture.............. But I have a lot of picture boxes as the above one which makes my application very slow...... .........So i came with an idea of using Photoshop reference(CS3 photoshop dll file) and want to add a brightness to that picture in a code.................... So please any body with an idea it is nice to me........ thnak you
|
|
|
|