|
|
Hi
maybe i am not making any sense..i am creating a HTML file on runtime and opening it in a Webbrowser control,the html also have links..instead of assigning html or other http file link in SRC tag,i want to call my c# function which grab the particular text from webbrowser control and pass it in some C# function,for instance,my HTML have links
1)Apple 2)Oranges,when i click Apple,then it calls MessageBox with text "Apple" etc..is it possible?how can I inject some code to call c# based routines
Thanks
|
|
|
|
|
I can think of two possible solutions to your problem.
The first is to hook-up an event handler for the browser control's BeforeNavigate2 event. You can then use this to parse special commands passed in the SRC attribute and execute particular methods. An example is shown below.
HTML:
Calls Host Form's MyCommand Method
C#:
private void WebBrowser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
// Determine if this is a proper url or a command
if (((string)e.uRL).IndexOf("command:") != -1)
{
// Call the appropriate function for the command
switch (((string)e.uRL).Replace("command:", ""))
{
case "mycommand":
this.MyCommand();
break;
}
// Stop the browser from performing the navigation
e.cancel = true;
}
}
The other method is to hook up some event sinks to capture the DHTML events.
Hope this helps.
Aaron
|
|
|
|
|
|
I hope my already 2 day search ends here !
This is what I want to be able to do: existing app A generates sql-qeurys and sends these as strings to app B (application to develop). These querys are send to a database server and the result is put into two different files (one file with result data layout and the other with actual result data).
Now app B must return a struct with information about these files(location etc) and some additional information to app A. App A reads the files and presents the information to the user.
My question now is: how do I send data (using structs with strings, integers etc) between two applications?
My intention is to use Window Messages for this task using SendMessage / WM_COPYDATA. I have not been able to find an example which made it (crystal)clear for me, maybe someone can help me tackle this problem.
Or do you think this approach is not the good one, please tell me!
Thanks in advance,
Darth
I can't get no satisfaction.
|
|
|
|
|
You could just serialize the sturcture and send it as a byte array from app B over a socket to app A and de-serialize it. This way App A and B do not neccessarily need to be on the same computer. Just an idea.
|
|
|
|
|
Sorry, just saw you were using WinCE, disregard my suggestion.....
|
|
|
|
|
Greetings,
I read somewhere that it is better to do a for loop rather than a foreach loop, as they said that it takes extra processing.
Aren't these doing exactly the same thing? It seems to me that the for loop would take more processing.
<code>
For(int i=0;i<myArrayList.Count;i++)
{
((MyClass)myArrayList[i]).myMember = 3;
}
Foreach(MyClass myClass in myArrayList)
{
myClass.myMember = 3;
}
</code>
Any insight would be greatly appreciated.
EB
|
|
|
|
|
foreach makes a call to the IEnumerable interface and gets an IEnumerator
the enumerator is then responsible for itteration through your list.
the little overhead that is involved in the foreach is the actual calls to the enumerator ".Current" and ".MoveNext"
In my oppinion you should use foreach since id take readable code over a very very minor performance increase any day..
unless i really really need the extra cpu cycles that is..
//Roger
|
|
|
|
|
I started using the foreach loops instead of the for loops and found that they are only to be used for read-only operations. (unless I'm missing somthing?) Looks like only the for loop will work if you want to write to the object. I've never used it before but the foreach seems to be working very fast and is nice for the read-only stuff...
Thanks for your reply Roger.
EB
|
|
|
|
|
|
Foreach is definitely slower than For, especially when iterating over typed arrays.
|
|
|
|
|
Robert Rohde wrote:
Foreach is definitely slower than For, especially when iterating over typed arrays.
That will change with generics in .NET 2.0.
|
|
|
|
|
Excellent, I am trying to squeeze every drop of resources that I can without the code being too cumbersome. Thanks for the confirmation on this... looks like I'm just going to stick with the plain-vanilla for-loops on this one.
EB
|
|
|
|
|
|
|
I have a class like the following. The DataClass2 type is also derived from ASuperObject.
public class DataClass1 : ASuperObject<br />
{<br />
private DataClass2 dataClass2;<br />
<br />
public DataClass1(){}<br />
<br />
public DataClass2 MyDataClass2<br />
{<br />
get<br />
{<br />
if(this.dataClass2 == null)<br />
this.dataClass2 = DataClass2Holder.Instance.Dummy;<br />
return this.dataClass2;<br />
}<br />
set{this.dataClass2 = value;}<br />
} <br />
}
From a function I fool around with an instance of DataClass1 and at some time I use the MyDataClass2 property, to get the dataClass2 value.
The dataClass2 has not been instantiated yet, so the 'if' clause sets the value.
Now the function that called the property would like to know, if the 'if' clause was invoked or not (see code below)- can this be done?
int localCount = 1;<br />
PropertyInfo[] properties = this.GetType().GetProperties();<br />
foreach(PropertyInfo property in properties)<br />
{<br />
if(property.PropertyType.BaseType == typeof(ASuperObject))<br />
{<br />
((ASuperObject)property.GetValue(this,null)).nameAddition += localCount+"_"; <br />
((ASuperObject)property.GetValue(this,null)).InitializeHierarchy();<br />
localCount++;<br />
}<br />
}
(it must be general and not just a bool being set in DataClass1)
|
|
|
|
|
spif2001 wrote:
it must be general and not just a bool being set in DataClass1
No - you have encapsulated the dataClass2 member variable and only permit access throught the MyDataClass2 property (which could do anything it liked). As the MyDataClass2 property is designed to always return a DataClass2 object (or one derived from it) then you can never know by what the state of the member variable was before.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
1. Solution:
Dont return a DataClass2 object but a structure with a DataClass2 and a boolean value (would require to change the type of the property).
2. Solution:
Instead of making a property make a method like:
<br />
public DataClass2 GetMyDataClass2(out bool tookedDummyObject) {<br />
if(this.dataClass2 == null) {<br />
this.dataClass2 = DataClass2Holder.Instance.Dummy;<br />
tookedDummyObject = true;<br />
} else {<br />
tookedDummyObject = false;<br />
}<br />
return this.dataClass2;<br />
}<br />
If you still want the property to be present (for other callers who do not need the extra info) it could be implemented like:
<br />
get<br />
{<br />
bool notNeeded;<br />
return GetMyDataClass2(out notNeeded)<br />
}<br />
|
|
|
|
|
Good solutions there, but I have to minimize the code added to the ASuperObject sub-classes.
Ended up with a boolean solution after all, namely adding a bool isDummy to the ASuperObject abstract class. Then in my DataClass2Holder(Singleton) i set the bool after the Dummy DataClass2 has been instantiated.
Then I don't need to alter the property impl. in DataClass1 and the Dummy becomes semi-invisible.
Hope I find a better solution along the way, but for now it will have to do.
Thanks for the help you both.
-spif2001
|
|
|
|
|
hi,
i downloaded the latest aticle/project published in this site regarding REFLECTION.Its working fine for "mscorlib.dll".If we replaced the existing dll with some other dll, its throwing exception as "file is invalid format".
Any prerequisties are there?
which type of dll's i have to give?
I want to give dynamically.
Thanks,
Naveen.
|
|
|
|
|
You should ask questions like this on the article's page, not here in the general forum.
mav
|
|
|
|
|
hi there,
i'm trying to write to xml doc. from a string which is assigned to parsed information from the web by using(regex):
string myString, myString2;
XmlTextWriter writer = new XmlTextWriter("data.xml", null);
writer.WriteStartDocument();
//Use automatic indentation for readability.
writer.Formatting = Formatting.Indented;
//Write the root element
writer.WriteStartElement("Schedule");
foreach(Match m3 in Regex.Matches(getPage, tm.ToString()))
{
Group g3 = m3.Groups[1];
Console.WriteLine(g3.ToString());
myString = g3.ToString();
//add sub-elements
writer.WriteElementString("Time", myString);
foreach(Match m3a in Regex.Matches(getPage, prog.ToString()))
{
Group g3a = m3a.Groups[1];
Console.WriteLine(g3a.ToString());
myString2 = g3a.ToString();
// //End the item element
// writer.WriteEndElement(); // end Rate
//add sub-elements
writer.WriteElementString("Programme", myString2);
//End the item element
writer.WriteEndElement(); // end Rate
}
}
// end the root element
//writer.WriteFullEndElement();
//Write the XML to file and close the writer
writer.Flush();
writer.Close();
}
i get this :05:00
Morning Reports
Wake Up to Money
Unhandled Exception: System.InvalidOperationException: Token StartElement in sta
te Epilog would result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName
, String ns)
at System.Xml.XmlWriter.WriteElementString(String localName, String ns, Strin
g value)
at System.Xml.XmlWriter.WriteElementString(String localName, String value)
at Scrape2.Scrape2.Main(String[] args) in c:\uni stuff\project stuff\scrape2\
scrape2.cs:line 83
any help plzz....
|
|
|
|
|
i actually need to alternate between the two foreach loops, i.e.
time
programme
time
programme
.
.
.
etc
|
|
|
|
|
How can I create the Thumbnail view from the form?
In the following approach we tried but we are facing some limitations to get the thumbnail image of the form alone.
Can anuy one please help how to creat the thumbnail of the form alone.
thanks!
Approach - I - Bitmap (screen capture method)
=============================================
Can able to create the thumbnail image using Bitmap and BitBlt.
Code Sample:
Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width,this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"c:\BaluCaptured.jpg", ImageFormat.Jpeg);
MessageBox.Show("Finished Saving Image");
Limitations Facing:
1) Not able to capture the non visible portion of the form.
2) If the specified region size is beyond the visible portion in the screen, then remaining portions are in black color.
Approach - II - Metafile
Can able create the image using Metafile approach. How can we create the metafile for user controls drawn objects (Example: Graphs, Gauges).
Graphics grph = this.CreateGraphics();
IntPtr ipHDC = grph.GetHdc();
Metafile mf = new Metafile(@"d:\TestBalu.emf", ipHDC, EmfType.EmfPlusDual);
//grph.ReleaseHdc(ipHDC);
//grph.Dispose();
grph = Graphics.FromImage(mf);
grph.DrawRectangle(Pens.Blue, 10, 10, 100, 120);
Point p1 =new Point(20,60);
Point p2 =new Point(40,80);
Point p3 =new Point(100,120);
Point p4 =new Point(120,260);
Rectangle re=new Rectangle(30,20,60,90);
grph.DrawBezier(Pens.Gold, p1,p4,p3,p2);
grph.DrawBezier(Pens.Gold, p2,p4,p3,p2);
grph.Dispose();
Limitations Facing:
1) This can be possible for regular Graphics objects like creating Rectangle, Ellipse... using System.Drawing class.
2) It is not supporting for 3rd Party controls like Dundas gauge controls.
When we try to create the metafile (emf) the file size shows 0KB. It is not writing the data in to the file.
Approach – III – Scale down the Form
How to clone the form which contains the graphics objects like rectangle, user controls?
When we are trying to clone, it is only referring the memory; it is not actually cloning the object.
Code Sample:
Form2 obj = new Form2();
obj.Width = 640;
obj.Height = 480;
obj.BackColor = Color.Green;
obj.Show();
Form obj1 = new Form2();
obj1 = obj;
obj1.MaximizeBox = false;
obj1.MinimizeBox = false;
obj1.ControlBox = false;
obj1.FormBorderStyle = FormBorderStyle.None;
obj1.Scale(0.2f, 0.2f);
obj1.Show();
Limitations Facing:
==================
In .net we don’t have direct clone method to clone the form object. How can we clone the form object?
Even we tried with IClonable Interface's clone method also. Can any body please explain the clone() implementation in detail?
Thanks,
With Regards,
Balu Ramachandran
|
|
|
|