|
Hi,
I need to parse the XML resulted after browsing to a url.
I already have a way to do this, but I'm not quite happy with it: I have a form with an AxWebBrowser in it, I navigate the webBrowser to the url, handle webBrowser_DocumentComplete and in there grab the XML and close the form.
Is there a better way of doing this without loading and hiding a form?
thanx
|
|
|
|
|
Do an HttpWebRequest[^] and grab it?
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Thanx!
It's official, I'm losing my mind...
|
|
|
|
|
I'm using the SetWindowsHookEx Win32 method to set a hook on window activation for my process. It's working fine until garbage collection occurs so I'm trying to pin the delegate using GCHandle.Alloc.
This is failing with an error message that the delegate is nonprimitive and nonblitable even though I've changed the method signature to this:
public delegate IntPtr HProc(IntPtr nCode, IntPtr wParam, IntPtr lParam);
How can I change the delegate so that I can use it, or is there a better approach altogether?
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I've run into a similar situation.
public delegate void ControlEventHandler(ConsoleEvent consoleEvent);
ControlEventHandler handler = new ControlEventHandler(OnControlEvent);
GC.KeepAlive(handler);
Not sure if this will help, but GC.KeepAlive will render the object ineligible for garbage collection.
Scott P
|
|
|
|
|
Thanks for the approach, but it turns out I didn't need it. The sample code I was using had the delegate as a local variable of the hooking class instead of an instance variable. Giving it the proper lifetime fixed the issue.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Is ClickOnce the preferred deployment strategy today for Winforms and WPF applications (rather than Windows Setup projects)?
|
|
|
|
|
I don't know if its a preferred method, but it doesn't hurt to be able to offer the option. Just depends what your customer wants. Let them choose basically...
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
I'm trying to get a very simple remotable type example working (from [url]http://msdn.microsoft.com/en-ie/library/xws7132e(en-us).aspx[/url] ).
I've put together the Remotable Type, the Server/Host and the Client exactly as in the tutorial. The Client is on a different machine from the other 2 (although you need to copy the RemotableType.dll to the client and add a reference to it in that project).
In my client, I configure the remote connection (specifying the machine etc. as in the tutorial) and then create my instance of the remotable class with the code below:
[CODE]RemotingConfiguration.Configure("Client.exe.config.txt", false);
RemotableType.RemotableType remoteObject = new RemotableType.RemotableType();[/CODE]
The trouble is, this is simply creating and running the remotableType on the Client machine. Is there something extra I need to do to actually get it to make that connection to the Server machine, have it run the code and return the result to the client as the tutorial says it does.
Thanks.
Conor.
|
|
|
|
|
Hi All,
If I have two classes with same names in two different namespaces. I need to type cast object of one class into another one. How can I do it. Pls. any help is very thankfull.
Thanks,
Aleem Mohammad.
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
use (namespace1.classname)namespace2.classname
Dave
|
|
|
|
|
indian143 wrote: I need to type cast object of one class into another one.
What? You can't cast a class into a type that it isn't, period. If it is the type then you use as .
Foo myFoo = myBar as Foo;
However if myBar is not a type Foo that will just produce a compiler error.
led mike
|
|
|
|
|
You can only really do this if one class inherits from the other. If there is no relation other than them sharing the same name, then you can't perform the cast. The only thing you could do is create an instance of the second class and copy the values from the first in. Here's an example where both objects have the same properties, but aren't the same class (and the same property names are present in both - it's an artificial example, but serves as an example):
private U Copy<T,U>(T original) where U : new()
{
PropertyInfo[] props = original.GetType().GetProperties();
U returnItem = new U();
foreach (PropertyInfo p in props)
{
returnItem.SetValue(returnItem, p.GetValue(original, null) null);
}
} I've just typed this off the top of my head, so some of the details may need to be finetuned a bit.
|
|
|
|
|
I'm studying for the MCTS and have just started developing my first custom control. The control seems to work perfectly when implemented in design time when dragged from the Toolbox to a test form, but when I try to implement/create the control dynamically in code, the control's overridden OnPaint method is not being accessed and the control is not being drawn when I run the program and try to create a new instance of the control in the Form's Load event.
I think I'm missing something fundamental in the control's constructor, but from what I've read about SetStyle method, using:
this.SetStyle(ControlStyles.UserPaint, true);
should have forced the control to paint itself via OnPaint -- but, it's had no effect. Using an Invalidate() call in the constructor also has no effect. Here's the code for the control as it stands now. The Control itself is essentially a label with a 'progress bar' drawn to a certain proportion of the control's width, then the base text is drawn above the bar.
Any thoughts on what changes are needed to ensure the OnPaint method is invoked when the control is instantiated/added at runtime would be appreciated!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ProgressBarLabel
{
[ToolboxBitmap(typeof(ProgressBar))]
public partial class ProgressBarLabel : Control
{
private float progressBarWidthRatio;
[Category("Appearance"),
Description("A number between 0.0 and 1.0 representing the % width of the ProgressBar in the Label.")]
public float ProgressBarWidthRatio
{
get
{
return this.progressBarWidthRatio;
}
set
{
this.progressBarWidthRatio = value;
if (this.progressBarWidthRatio > 1.0)
{
this.progressBarWidthRatio = 1.0F;
}
else if (this.progressBarWidthRatio < 0)
{
this.progressBarWidthRatio = 0.0F;
}
Refresh();
}
}
private Color progressBarBackColor;
[Category("Appearance"), Description("The BackColor of the ProgressBar within the Label.")]
public Color ProgressBarBackColor
{
get
{
return this.progressBarBackColor;
}
set
{
this.progressBarBackColor = value;
Refresh();
}
}
public ProgressBarLabel()
{
this.progressBarWidthRatio = 0.0F;
this.progressBarBackColor = this.BackColor;
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
public override string Text
{
get
{
return base.Text;
}
set
{
this.Invalidate();
base.Text = value;
}
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
Rectangle r = pe.ClipRectangle;
Brush pbBrush = new SolidBrush(progressBarBackColor);
g.FillRectangle(pbBrush, r.X, r.Y, r.Width * progressBarWidthRatio, r.Height);
g.DrawRectangle(Pens.Black, r.X, r.Y, r.Width - 1, r.Height - 1);
g.DrawRectangle(Pens.WhiteSmoke, r.X + 1, r.Y + 1, r.Width - 2, r.Height - 2);
SizeF timeSize = g.MeasureString(base.Text, base.Font);
g.DrawString(base.Text, base.Font, new SolidBrush(base.ForeColor),
(r.Width - timeSize.Width) / 2, (r.Height - timeSize.Height) / 2);
g.Dispose();
}
}
}
|
|
|
|
|
rcaciopp wrote: the control is not being drawn when I run the program and try to create a new instance of the control in the Form's Load event.
Are you adding it to the Form correctly?
led mike
|
|
|
|
|
Think so. This code compiles and runs without error. If I do a step through, I clearly see the code hit the control's constructor but skips the OnPaint() method.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TestNewControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ProgressBarLabel.ProgressBarLabel myPBL = new ProgressBarLabel.ProgressBarLabel();
myPBL.ProgressBarBackColor = Color.Blue;
myPBL.ProgressBarWidthRatio = 0.5F;
myPBL.Text = "Runtime";
myPBL.Location = new Point(15, 15);
this.Controls.Add(myPBL);
}
}
}
|
|
|
|
|
Did you compare the generated code for the control in InitializeComponent() versus your own hand written code??
|
|
|
|
|
Yes, I did. Hmmm. This time around I guess I'm reading a difference in that it generates a SuspendLayout() / ResumeLayout() call. I'm frankly not yet familiar with these methods vs. just looking at the progressBarLabel1....Otherwise, I don't see anything that 'turns the switch' to invoke OnPaint(). Here's the Designer-generated code for a dragged/dropped ProgressBarLabel:
private void InitializeComponent()
{
this.progressBarLabel1 = new ProgressBarLabel.ProgressBarLabel();
this.SuspendLayout();
this.progressBarLabel1.Location = new System.Drawing.Point(78, 122);
this.progressBarLabel1.Name = "progressBarLabel1";
this.progressBarLabel1.ProgressBarBackColor = System.Drawing.SystemColors.Control;
this.progressBarLabel1.ProgressBarWidthRatio = 0F;
this.progressBarLabel1.Size = new System.Drawing.Size(137, 23);
this.progressBarLabel1.TabIndex = 0;
this.progressBarLabel1.Text = "progressBarLabel1";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.progressBarLabel1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
|
|
|
|
|
SuspendLayout and ResumeLayout are just to tell the form not to do the control updating as it's initializing a lot of controls. Should not affect it.
Try defining the control in the form, not in the Form_Load, and set each properties as what's set in InitializeComponent (Name, Size)
|
|
|
|
|
Wow, Dark....the solution!
Interesting that something as innocent to my newbie-self as setting the size of the object would have the effect of firing the OnPaint() method. I had assumed that the Size property would be created when the constructor hit the OnPaint method, but in fact it seems that the compiler will not fire OnPaint up at all without a Size being set.
FYI - this code added to either a method other than Form_Load or to Form_Load works just fine to add my control to the Form:
private void Form1_Load(object sender, EventArgs e)
{
myPBL = new ProgressBarLabel.ProgressBarLabel();
myPBL.Location = new System.Drawing.Point(15, 15);
myPBL.Name = "progressBarLabel2";
myPBL.ProgressBarBackColor = System.Drawing.SystemColors.Control;
myPBL.ProgressBarWidthRatio = 0F;
myPBL.Size = new System.Drawing.Size(137, 23);
myPBL.TabIndex = 2;
myPBL.Text = "progressBarLabel1";
this.Controls.Add(myPBL);
}
If you comment out this line:
myPBL.Size = new System.Drawing.Size(137, 23);
I can reproduce the error. Really nice to know. Thanks for your help, Dark!
|
|
|
|
|
I got a problem with parsing dates from strings.
I know the dates are always in the English format but when you convert or parse dates from a string it depends on the current culture of PC where the program is running.
This means if the culture isn't English, it's not possible to properly parse any date.
Is there any way of ignoring the current culture when parsing dates?
Thanks in advance.
|
|
|
|
|
Hi,
the DateTime class has Parse and TryParse methods that optionally take an IFormatProvider,
so you can fix the acceptable format.
|
|
|
|
|
Or ParseExact ?
But try to always use an ISO 8601 format: yyyy-MM-dd
|
|
|
|
|
Thanks a lot!
The ISO 8601 format works great.
|
|
|
|
|
I've got an xcopy command in my post build event. It's meant to write my files to a network machine that will create the final packages. The drive X: is mapped to that network drive
It's using $ProjectPath to build the path but this is the command that i see being executed in the output window:
xcopy /E /Y "C:\Users\russell.jones\Documents\Visual Studio 2005\Projects\DataViewer\..\..\OutputFiles\*.*" "X:\My Build Files\Files"
There's no visible error and the filenames all scroll merrily past but the files never arrive in the destination.
Running the command in a shell works fine and the files copy over perfectly.
In case it makes a difference I'm using the cursèd OS but visual studio is running as admin. I have rights to the share and can browse delete files on the share via shell or UI.
has anyone else suffered similar problems in post build events?
Cheers
Russell
|
|
|
|