|
Why, don't you just use Process.Start () and open the fil in the default application?
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
yes I could, but the application that will eventually use the files on this list (not the same as mine) might not have the same default applications. And that app will also want to start the files listed here in IE through plug-ins. So I need to supply the same functionality here...
|
|
|
|
|
I really don't get why you need to view the files in a browser.
Why would you, for instance, like to open a pdf in a browser.
If he has a plugin for the browser you can be shure he has a standalone application for that file type.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
misterbear wrote:
Is there such a thing as an internet explorer control available that I can embed easily?
IE can be embedded as an ActiveX control within your application. If you add the "Microsoft Web Browser Control" COM Component (shdocvw.dll) to your Toolbox, you'll be able to insert that on your form. To visit a website, call the control's Navigate function. The Web Browser control is heavily documented on MSDN, and many examples exist on the 'net for showing some of the advanced things you can do with it.
|
|
|
|
|
In addition to what CWIZO and John said, you can interop shdocvw.dll by using tlbimp.exe or VS.NET (add a COM reference to your project for the Microsoft Web Browser library) and use the InternetExplorer class to load a file. This will create a new instance of IE or use an existing instance (the fore-most instance, IIRC) to display the HTML (or whatever IE-handled file). Using Process.Start with a filename (works like ShellExecute(Ex) ) will use the default browser, but if you want to make sure they use IE (maybe the HTML files are scripted only for IE, for example) use the InternetExplorer object or use Process.Start("iexplore.exe", pathToHtmlFile) .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
just a quick question. How can I make sure that a message box opens over all open windows. For example, the application is testing for a certain event every 10 seconds but the user might be browsing the internet or using word when the event occurs. I need the message box from the app to appear over all windows that are open to let the user know that the event has occurred. I'd imagine its straight forward but I have tried setting focus on the form or bringing it to front in the line before the MessageBox.show line but the message box doesnt pop up over the windows I have open. As I said, its probably simple but its driving me mad!!,
Regards,
John
|
|
|
|
|
First, don't use MessageBox.
Create your own message box form and set it's TopMost property to true. When you want to show the form, set it's message property or call a method to set the message (which you also have to provide) and then just creat a new instance of the form and call .ShowDialog().
myMsgBox msg = new myMsgBox;
myMsgBox.Message = "Some message...";
myMsgBox.TopMost = true;
myMsgBox.ShowDialog();
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Try this.
using System;<br />
using System.Runtime.InteropServices;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public class Hi : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Button button1;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Hi()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
private void InitializeComponent()<br />
{<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
<br />
this.button1.Location = new System.Drawing.Point(64, 104);<br />
this.button1.Name = "button1";<br />
this.button1.TabIndex = 0;<br />
this.button1.Text = "button1";<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 273);<br />
this.Controls.Add(this.button1);<br />
this.Name = "Hi";<br />
this.Text = "Hiiii";<br />
this.Load += new System.EventHandler(this.Form1_Load);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Hi());<br />
}<br />
<br />
[DllImport("user32.dll")]<br />
public static extern bool SetForegroundWindow(IntPtr hWnd);<br />
<br />
[DllImport("user32.dll")]<br />
public static extern IntPtr FindWindow(string lpClassName,<br />
string lpWindowName);<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
System.Threading.Thread.Sleep(10000);<br />
IntPtr ptr = FindWindow(null, "Hiiii");<br />
SetForegroundWindow(ptr);<br />
MessageBox.Show("In fornt");<br />
}<br />
}<br />
}
|
|
|
|
|
hi,
i need to capture keypress event in datagrid. but i wrote keypress event in datagrid. but the event is not fired. please help any one. i need to change cursor position from cell to another thru program. i need to capture ENTER key.
Thanks in Advance!
Have A Nice Day!
Murali.M
|
|
|
|
|
Please post your code when you have a question, it helps us find out what you're doing wrong. Ive just created a KeyPress event handler in VS2003 and when i press Enter on my DataGrid my MessageBox is shown.
private void dataInvoice_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
MessageBox.Show("Testing");<br />
}
This was done by double clicking the KeyPress event in the properties window for the DataGrid. If this does not help then please post your code and someone should be able to point you in the right direction.
Kev Pearman MCP
|
|
|
|
|
I would be very interested if it is possible to add an item to a context menu (e.g.in Outlook) or in a menu in general (again Outlook).
If it is I would be very interested what the code has to look like to add the item.
So if someone is willing to share this code section it would be very interesting for me to try this out myself!
|
|
|
|
|
|
I would be interested in this, too!
But I can't find this posting you are refering to!
Could you please be a little more specific or do you have a link to the posting?
Thanks!
Stephan.
|
|
|
|
|
well, as far as I know I once read of someone who said you have to clone the existing menu, do a lot of castings and dig deep into the microsoft model to do this.
I once wanted to do this myself but after 14 days of doing this and that I gave up because I had no real result, which was worth working on it any further.
So from my point of view I would say do insert a button, that's much more easy to do. And if you finally did it this way and everything works and there is still some amount of time you could still try do some research or testings on you aim.
But don't mess up to long wasting time because you do want your solution to be 100% the way you planned it. Beliefe me: You do have to change opinions quit often while designing big proggies!
|
|
|
|
|
Hi there, my question is:
How do I automatically resize the Form when the screen resolution changes between design-time and runtime?
My application is developed with 1024 * 768 but i am not sure that all users do use this resolution. and i don`t want to change the users resolution programtically by using user32.dll. I want my application to adjust to users resolution.
Please help me out
|
|
|
|
|
#1, no matter method you use to solve the resizing, you'll probably want to trap your Form's "Resize" event (in the designer, select your form, in the properties window, click the "Events" icon, find Resize, double click it). Trapping the Form's resize will make it easier to resize all the child controls. If you have subcontrols that don't respond well to a parent resize, develop a public method within them that you can call to initiate the same type of resizing once your main form is resized.
#2, I don't know the exact way to get the "true" screen resolution in WinForms (just been using them seriously for about a week now). Screen.PrimaryScreen.WorkingArea (a System.Drawing.Rectangle property) will get you very close -- it returns the largest client area. On my 1280x1024 resolution screen, it returns 1280x994. As a note right here, you probably shouldn't hardcode in "30" or whatever number you find to be the difference between the true resolution and what you see with .WorkingArea. For instance, if I docked my taskbar to the right side of the screen, it would be my X component vs Y component that would shrink. So .WorkingArea may be the best bet anyhow if you truly want to make your UI look standard across all setups.
As far as solutions, there's a couple things you can do:
- Make calculations based on the design time form placement and size vs. the resolution returned by .WorkingArea (basically, come up with fractions/scaling factors/offsets that you can use to dynamically position your objects).
- Do the same as above, but assume a constant, virtual screen size (I've used 5000x5000 before in games). Calculate scales & offsets, probably only need to do this once in your app at the beginning and store the results in sub-properties of the controls if possible, or in some form of List. Then when resize time comes, apply the stored fractional value and multiple/divide it with the virtual screen size : actual screen size (.WorkingArea or other) to come up with the form's true placement.
The second may sound like a lot of work, but sometimes it's nice to initially work with constant units, then just have your program rescale for you when the Resize occurs.
I'm pasting some sample code of the first method I recommended. Note that I use relative offsets in some cases, which is perfectly fine:
lblLoans.Location = new Point(lblLoans.Location.X,(int)((double)Size.Height * 0.5));
lvwShares.Size = new Size(Size.Width - 16, lblLoans.Location.Y - 60);
lvwLoans.Location = new Point(lvwLoans.Location.X,lblLoans.Location.Y + 25);
lvwLoans.Size = new Size(lvwShares.Size.Width,lvwShares.Size.Height);
Size.Width / Size.Height refer to the size of the Form (since this is in my Form's resize method).
Lastly, and I don't have a solution for this, you may want to consider what will happen when the user changes resolution while using your application -- though MANY programs do not properly handle this, you will have accounted for many things a user could do which might cause your UI to break. Ideally, you'd be able to detect the screen resolution change (somehow?) and reset a member variable to reflect the new values, then use these for future calculations. In the Win32 API, there was a message you could trap which would let you know the screen resolution was changed, but I'm not quite sure how to detect that in WinForms....
Good Luck!!
|
|
|
|
|
Regarding your second answer, if you read the .NET Framework SDK documentation, WorkingArea is the desktop area minus any app bars (like the task bar), docked windows, etc.. Use Screen.Bounds to get the entire client area.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
See my indirect reply to part of your question at http://www.codeproject.com/script/comments/forums.asp?msg=889799&forumid=1649#xx889799xx
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please i want to creat a button when i click on it open other form.if i added a new form to the project how can i open it by clicking a button in anther form???!!!.
|
|
|
|
|
hi,
No one is perfect in any language.Language is used for convince your idea or things to others. But here i don't know what you are trying to convince.
so please write your queary which help others to post answers.
Don't feel bad i can help you out.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Suppose Form1 contains button1 and when user clicks button1, you want to display Form2. Below code does the same.
private void button1_Click(object sender, System.EventArgs e)
{
using (Form2 f = new Form2())
{
f.ShowDialog();
}
}
|
|
|
|
|
Firstly create an instance of your new form
Form2 myForm = new Form2();
Then show the form
myForm.Show();
If this was not what you were trying to do then re-post your problem.
Kev Pearman MCP
|
|
|
|
|
Hi,
Is it possible for a base class to determine with reflection the type of the derived class that called the base constructor?
Something like the following code:
--------------------------
class DerivedClass : BaseClass
{
public DerivedClass() : base() {} // 1.
}
class BaseClass
{
public BaseClass() // 2.
{
Console.WriteLine("I was constructed by the following derived class: "+ ... );
}
}
---------------------------
Thanks,
Pete
|
|
|
|
|
Yes it can..
using System;<br />
namespace ConsoleApplication1<br />
{<br />
class Class1<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
c1 c = new c2();<br />
Console.WriteLine("I was constructed by the following derived class: "<br />
+ c.GetType());<br />
c = new c3();<br />
Console.WriteLine("I was constructed by the following derived class: "<br />
+ c.GetType());<br />
}<br />
}<br />
class c1<br />
{<br />
public c1(){}<br />
}<br />
class c2 : c1<br />
{<br />
public c2(){}<br />
}<br />
class c3 : c1<br />
{<br />
public c3(){}<br />
}<br />
}
|
|
|
|
|
PJules wrote:
Is it possible for a base class to determine with reflection the type of the derived class that called the base constructor?
Ok had to read that a few times. I think I have, quite tricky! I think this will explain what you need:
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection;
#endregion
namespace ConsoleApplication1
{
class Program
{
protected Program()
{
Console.WriteLine("{0:X8}\t:default", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
protected Program(string overload)
{
Console.WriteLine("{0:X8}\t:overload", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
protected Program(int someother) : this(someother.ToString())
{
Console.WriteLine("{0:X8}\t:overload -> someother", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
static void Main(string[] args)
{
Derived a = new Derived();
Derived b = new Derived("foo");
Derived c = new Derived(100);
Derived d = new Derived(true);
Console.ReadLine();
}
}
class Derived : Program
{
public Derived() : base("dummy") { }
public Derived(string overload) : base(100) { }
public Derived(int crossref) : base() { }
public Derived(bool v) : this() { }
}
}
Output:
03B95145 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419 :overload -> someother
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
03DEA808 :default
ConsoleApplication1.Program::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Int32)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
02A8E964 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Boolean)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
Got it? Good
top secret xacc-ide 0.0.1
|
|
|
|
|