|
A document that includes frames links to other documents - one for each frame. You must get the frame count from the top-level document and enumerate through each frame. Also, don't instantiate myDoc - you're getting an instance from WB.Document . There is absolutely no reason to instantiate it and you're just adding memory overhead anyway.
An example follows:
IHTMLDocument2 doc = (IHTMLDocument2)WB.Document;
if (doc != null)
{
int len = doc.frames.length;
if (len > 0)
{
IHTMLWindow2 window = null;
IHTMLDocument2 frameDoc = null;
for (int i=0; i<len; i++)
{
object index = i;
window = (IHTMLWindow2)doc.frames.item(ref index);
if (window != null)
{
frameDoc = window.document;
if (frameDoc != null)
Console.WriteLine(frameDoc.body.innerHTML);
}
}
}
else
Console.WriteLine(doc.body.innerHTML);
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi,
I've got a customized datetime picker that includes a popup modal dialog. I need to make sure the popup stays completely on the users screen so they can close the control (button is at the bottom). Are there any functions available to tell me that it's being clipped?
thanks,
Deanna
|
|
|
|
|
There are several ways of doing this. If you're using a system modal dialog (set TopMost to true on your Form ), you can determine if the PaintEventArgs.ClipRectangle is equal to your client Bounds in your OnPaint override:
protected override void OnPaint(PaintEventArgs e)
{
if (e.ClipRectangle != Bounds) { }
base.OnPaint(e);
} This works because you're a system modal dialog. The only thing hiding it is either another system modal dialog (the likeliness of another is unlikely in most circumstances, especially based on what your dialog is prompting for) or it's outside the screen area.
There's much better ways of doing this, though. You could use properties of the Screen class and methods of the Rectangle struct to determine extents. You could even prevent the dialog from extending past the screen, something we've discussed in the past here (click "Search comments" above).
Yet another way - and most likely more pleasing to users and better regarding usability - is to popup the window directly above or below the DateTimePicker (or whatever you're using), much like the standard DateTimePicker does. This is a common user interface and presents a common user experience, something the Windows UI Guidelines drive. Having a popup window appear distant from the value could be consfusing for some users and annoying for others that get frustrated with having to look all over their screen (I know I would). Just make the popup window borderless and they can't move it. That's much like specifing the WS_POPUP window style for the dialog if you were natively coding such a control.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks Heath. Yes, normally the popup is located right below the main control, but if the main control is too near the bottom of the screen I want it to go up top instead.
|
|
|
|
|
I am trying to do the simplest thing with the Windows Forms .NET DataGrid Control. I want to simply bind a recordset from a SQL statement at runtime. This code shows what I am TRYING to do.
String connStr = "Data Source=(local); database=plandata; User ID=sa; pwd=";<br />
SqlConnection conn = new SqlConnection(connStr);<br />
String st;<br />
st = "select * from relationships";<br />
SqlCommand cmd = new SqlCommand(st,conn);<br />
conn.Open();<br />
<br />
dataGrid1.DataSource = cmd.ExecuteReader();<br />
dataGrid1.DataBind();
Apparently it is not this easy. When I attempt to call DataBind(), I get an error saying I have to use IList or IListSource.
Can someone show me how I do this? I can't find an example anywhere. I need to bind at runtime, not design time.
Thanks!
Mark
|
|
|
|
|
Read the values into a DataTable then set the DataSource to that table.
If you are going to have multiple tables then put them into a DataSet and use the DataSet as the source.
Kev
|
|
|
|
|
Kev,
That sounds good. Thanks.
But will a DataTable hold large tables with dozens of columns and thousands of rows? For instance, SQL Query Analyzer will easily display a huge table with thousands of rows. Will this technique be comparable?
Thanks again!
Mark
|
|
|
|
|
Mark,
I wrote an app for our office that analyses text files each week and puts the result into a dataset which can then be used to update our Data Warehouse. I'm not sure on the limitations but we run the program once a week and it deals with 25,000 +rows each time. This can be output to a datagrid without any problems but i suppose it will depend on the memory / processor in the machine.
Hope that's OK for ya.
Kev
|
|
|
|
|
Hi..
I have a specification sheet which has a horizontal scrool bar..
I would like to know what is the windows notify message sent when i move the horizontal scroll bar. I tried WM_HSCROLL but it was not working for me..
Can any one help me in this reg.
Thanks
Sudhakar
|
|
|
|
|
Make sure WM_HSCROLL and WM_VSCROLL are defined correctly, as in this example:
using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Label lbl;
Test()
{
Text = "Sample";
AutoScroll = true;
lbl = new Label();
Controls.Add(lbl);
lbl.Location = new Point(0, 0);
lbl.Size = Size + Size;
lbl.TextAlign = ContentAlignment.MiddleCenter;
}
protected override void OnResize(EventArgs e)
{
lbl.Size = Size + Size;
base.OnResize(e);
}
const int WM_HSCROLL = 0x0114;
const int WM_VSCROLL = 0x0115;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HSCROLL)
{
lbl.Text = string.Format("HPos: {0}", HIWORD((int)m.WParam));
}
if (m.Msg == WM_VSCROLL)
{
lbl.Text = string.Format("VPos: {0}", HIWORD((int)m.WParam));
}
base.WndProc(ref m);
}
int HIWORD(int dword)
{
return dword >> 16;
}
} (Scroll to the center and watch the values change)
You can also use the AutoScrollPosition for a ScrollableControl derivative, which includes (but is not limited to) Panel , UserControl , and Form .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I've been trying to start an application running in a minimsed mode and thought i could use ProcessStartInfo to do this. I created a new ProcessStartInfo instance.
ProcessStartInfo startInfo = new ProcessStartInfo("calc");
and set
startInfo.WindowStyle = ProcessWindowStyle.Minimized .
To run the application i used the line
Process.Start(startInfo);
After reading the help file on the ProcessStartInfo class i assumed this would start the application, calc, minimised to the task bar but it doesn't. It starts calc fine but it's just in a normal window.
Any suggestions?
Kev
|
|
|
|
|
This doesn't work with every application. Some application may retain window position and other state information written to storage when closed and reapply that state information when opened. This is often the case.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks for the tip, just tried it with a command window app and it minimizes the window fine. Is there any way to override the loaded state information? It doesn't matter that much because it's an in house application but it would be nice.
Cheers
Kev
|
|
|
|
|
Hi all,
I need to remember the selection ( eg. the radiobutton ) that the user selected even after the program closes so that the next time the program opens, the previously selected option whill be chosen. How can I do this?
There's a property in Visual Studio.NET call dynamic properties, is this the answer to solving this problem? Thanks in advance.
|
|
|
|
|
Why not just save the values in a text or binary file using
System.IO.StreamWriter / StreamReader or
System.IO.BinaryWriter / BinaryReader
Save the settings in form_Closing and read them in again in form_Load.
Kev
|
|
|
|
|
IsolatedStorageFile
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
|
i have this code in wich i define a local variable t3 of type DataTable.
i want to overwrite this code so that i get the same output BUT i should not define any Local variable !!!
please help me !!
Hint : DataSet can be added to the solution
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Net ;
using System.Net.Sockets ;
namespace AddRowTOGrid
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.TextBox txtSource;
private System.Windows.Forms.DataGrid dataGrid1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
DataTable t3 = new DataTable();
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnAdd = new System.Windows.Forms.Button();
this.txtSource = new System.Windows.Forms.TextBox();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(88, 80);
this.btnAdd.Name = "btnAdd";
this.btnAdd.TabIndex = 0;
this.btnAdd.Text = "ADD";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// txtSource
//
this.txtSource.Location = new System.Drawing.Point(192, 80);
this.txtSource.Name = "txtSource";
this.txtSource.Size = new System.Drawing.Size(104, 20);
this.txtSource.TabIndex = 1;
this.txtSource.Text = "";
this.txtSource.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtSource_KeyPress);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 165);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.RowHeaderWidth = 32;
this.dataGrid1.Size = new System.Drawing.Size(400, 112);
this.dataGrid1.TabIndex = 2;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 277);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.txtSource);
this.Controls.Add(this.btnAdd);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
if ( txtSource.Text.ToString()!="")
{
t3.Rows.Add(getSource());
txtSource.Text="";
}
else
MessageBox.Show("Empty Row Can't Be Added");
}
private string[] getSource()
{
string s = txtSource.Text.ToString();
string [] data = new string[]{s} ;
return data ;
}
private void Form1_Load(object sender, System.EventArgs e)
{
AddCR();
}
private void AddCR()
{
DataTable t = new DataTable("Test");
DataRow dtR;
dtR = t.NewRow();
t.Columns.Add();
dataGrid1.DataSource = t ;
t3 = t ;
}
private void txtSource_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ( e.KeyChar==13 )
if ( txtSource.Text!="")
{
t3.Rows.Add(getSource());
txtSource.Text="";
}
else
MessageBox.Show("Empty Row Can't Be Added");
}
}
}
|
|
|
|
|
Are you saying that you dont want to define t3 but you still want to display the information that you would have put in t3 in your datagrid?
Any particular reason why you don't want to define a table variable?
Kev
|
|
|
|
|
hi
my supervisor want me to do that , just for security matters
can u help me ?
he told me that i can declare a DataSet in the addRC() function , and retrive this DataSet from the button1_Click() ..
any thing to help me with ??
|
|
|
|
|
What addRC() function??
If you use a dataset then to the best of my knowledge you still need to use a datatable but you don't have to declare tehm first because the DataSet calss has a tables collection.
DataSet.Tables.Add()
You can add a new table to your dataset using the above code
once you have added the table to the dataset you can refer to it by
DataSet.Tables[0];
Then you can set up your table programaticaly and your away.
Hope this solves your problem
Kev
|
|
|
|
|
Help please,
I got some .dll written in Clarion 5.5. Can I (and how!) call it from my c# application.
Boris
|
|
|
|
|
How to convert string or StringBuilder to System.IO.Stream using C# ?
pls guide
|
|
|
|
|
|
If you haven't the option to use StringWriter, use MemoryStream and Convert.GetBytes
|
|
|
|