|
Hello!
I have a very specific question and that is about how to inherit a control for example the control System.Windows.Forms.TextBox without causing the environment to delete the control when there are some compile errors. It's the same problem with any visual control that you inherit. The control is deleted as soon as you use the View Designer when there is compile error.
It's very easy to reproduce my problem. You can do it in this way.
1. Create a class called ExtTextBox like this. In my example here I have removed the namespace. But if you include namespace make sure you have access to it.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}
As you can see this class ExtTextBox inherit from the ordinary components System.Windows.Forms.TextBox in the .NET framework
2. Create a windows form with any name. The default is Form1
3. Use the View Designer and create the control TextBox in the window form.
My control was called textBox1
4. Because I want the control textBox1 to be an instance of ExtTextBox I have to edit the InitializeComponent() I don't have any other idea.
Here is an extract from my windows form called Form1.
Only the interesting rows is written. Two rows are important here.
First saying that control textBox1 is of type ExtTextBox.
Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox.
public class Form1 : Form
{
private ExtTextBox textBox1; // First saying that control textBox1 is of type ExtTextBox.
...
...
...
Private void InitializeComponent()
{
//Second edit the InitializeComponent and say that textBox1 is an instance of ExtTextBox
this.textBox1= new ExtTextBox();
...
...
...
}
}
5 Compile. Hopefully you don't get any compile errors. When you run the application only the textBox is being displayed. The problem might start even here. If you get any compile error and you use the View Designer the control named textBox1 is being deleted automatically.
6 If you don't get any compile error make a change so you get a compile error and then use the View Designer the control named textBox1 is being deleted automatically.
7 Now to my question. I can't use controls that being deleted automatically when I get compile error.
8. If I want to use inheritance on visual control how do I do. I just can't have it as it is now.
9 I just can't use inheritance in the way I do now.
10. I hope that you have a good suggestion how I should use inheritance on visual control to avoid this kind of problems.
//Tony
|
|
|
|
|
Which version of VS.NET are you using? If it's 2005 then the custom control should be available in the toolbox.
If it's 2002 or 2003 I'll try and have a look at it but I can't remember since I havn't done any dev work on them in the last 6 months or so. But I seem to remember coming across this problem. The easiest solution I seem to remember I found was to create a new project (where possible) for containing these custom controls and reference this from the application. I know this isn't as clean a solution but it was the most reliable.
Ed
|
|
|
|
|
Hello!!
Thanks for your answer.
I use VS 2003.
I can't understand how your solution can solve my problem.
Can you be be specific.
//Tony
|
|
|
|
|
What my work-around was was to create a new project (within the same solution) for containing the controls. So you'd have e.g. Application.csproj contained in Project.sln, if you create a Controls project in your solution to contain the controls.
Then when you want to put them on the form VS2003 should have automatically added a toolbox entry for the control. If not you can add it to the toolbox manually. (Sometimes if an you've updated the custom control you may need to remove the assembly which contains the control from the debug/release folder of your project to force VS to get a new copy)
Ed
|
|
|
|
|
How to get file from internet? I have URL(http).
If file in ...\Temporary Internet Files\ - how to get file from ...\Temporary Internet Files\?
-- modified at 5:59 Wednesday 15th March, 2006
|
|
|
|
|
I think you'd be better off programmatically retrieving the file from the net, rather than hoping it ends up in the temporary internet files. You can use HttpWebRequest and HttpWebResponse with a bit of stream handling in .NET for this.
Regards,
Rob Philpott.
|
|
|
|
|
In .NET 2 there is a very useful class called WebClient in the System.Net namespace.
There is a function: WebClient.DownloadFile where you specify the URL and the path on the local machine to download to. (Also supports asynchronous downloads)
Ed
|
|
|
|
|
I'm using a WebBrowser to open Excel documents in a C# app. It all works as planned until you have a session of Excel already open - then I can't move focus back to the existing Excel session. Any ideas?!
Thanks.
|
|
|
|
|
Win32 API to find out which window you want and then use the API to select the window?
Ed
|
|
|
|
|
Hi, I'm not quite sure what you are saying... I'm not trying to programatically set focus to Excel, when Excel is clicked on by the user, the hosted document in the webbrowser stays active and won't shift to the actual instance of Excel. Are you suggesting to intercept the WMessages? If so, how do you distinguish between those on the hosted document and those of a valid excel document? Thanks.
|
|
|
|
|
Sorry I'm still not 100% clear on what you're attempting.
Is it:
- When the user runs Excel and your program together, your program will not allow Excel to receive focus?
- You're launching Excel based on a link in the hosted document?
Ed
|
|
|
|
|
No problem, appreciate the help! The sequence that doesn't work is:
1. A user opens and starts using excel.
2. Later, they open my app which has a webbrowser that can load office docs.
3. When viewing an excel file loaded into the webbrowser, the user can't return to their original excel docs (openned natively in excel).
Cheers.
|
|
|
|
|
Is the excel sheet inside the browser or does the browser load the doc in Excel itself?
Ed
|
|
|
|
|
|
So if I understood you correctly you have an Excel instance open (standalone) with a.xls open.
You open your program and open say b.xls inside the browser and cannot while your program is open access or set the focus to the instance of excel which has a.xls open until you close your program?
I can't think of anything at the moment which would cause this, would it be possible to have a copy of the program or some sample code which exhibits the same problem? (I'm running Win2K & Office 2003 for your information)
Ed
|
|
|
|
|
If you:
1. Start a new c# windows app project.
2. drag a webbrowser onto the form.
3. drag a openfiledialog onto it.
4. at the end of the constructor, put:
openFileDialog1.Filter = "Excel Files (*.xls)|*.xls";
if (DialogResult.OK == openFileDialog1.ShowDialog())
{
axWebBrowser1.Navigate(openFileDialog1.FileName);
}
5. open excel and start a workbook.
6. run your app and open a workbook.
7. try to activate (5).
Cheers.
|
|
|
|
|
Interesting behaviour, I see if I can find some time to look into it, but I've got deadlines to meet with coursework and exams coming up soon so it's a bit hit or miss.
Sorry, but at least you're not the only one. Does this happen with word docs as well?
Ed
|
|
|
|
|
No. Word was ok - although when playing around with Word I found some equally dubious problems but can't remember what exactly they were... Thanks for taking the time out.
|
|
|
|
|
Typical MS
Ed
|
|
|
|
|
Has anyone had any luck solving this problem?
I'm currently experiencing a similar problem, only I am displaying 2 excel files in 2 child WebBrowser controls. After the second WebBrowser navigates to its respective excel file (with the first WebBrowser already displaying its excel file) and then setting the focus back to the first window the strange things happen when you try to manipulate cell data or worksheets. (When editing a cell, the text is not displayed in the cell but is displayed on the formula bar on the second WebBrowser. When switching worksheets via the tabs, the sheet disappears from the first WebBrowser and shows up in the second WebBrowser.) It's like the last WebBrowser that opens an Excel file monopolizes the focus of the Excel App instance.
As a test, I tried opening the files in 2 separate Internet Explorer windows to see if the behavior could be reproduced. It isn't. The two excel files can be worked with without any problems.
|
|
|
|
|
It might be something to do with the fact that the WebBrowser control's a wrapper around the OCX version but I know that I've got a PITA problem where the browser grabs focus even though it's hidden, disabled, told to handle nothing and it's wrapped around inside a Component that's on the form.
It'd be nice if someone wrote a fully managed browser...
As of how to accomplish that have you ever tried Google?
Failing that try .
|
|
|
|
|
i need an example to create graph from C#
|
|
|
|
|
I want in my RichTextBox this action to do: Backspace key takes the same action like left arrow key. Speaking generally I don`t want to delete characters by backspace key inside the textBox field unless it is the last character.
This code works in TextBox (do the action which I want) but unfortunatelly doesn`t work in RichTextBox.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
<br />
char c = e.KeyChar;<br />
int start = textBox1.SelectionStart;<br />
int lenght = textBox1.Text.Length;<br />
<br />
if(c == (short)Keys.Back && start!=lenght)<br />
{<br />
e.Handled = true;<br />
SendKeys.Send("{LEFT}");<br />
return;<br />
}<br />
}
Can anyone help me?
|
|
|
|
|
Describe "how it is not working".
Do you get a error or what?
And aI think making this kind of behaviour is bad. There are standards and I hope you have a really god reason for doing this...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
You asked me why it doesn`t work. It takes two action in the same time. First it deletes charakters (so backspace key works like should work), second it moves cursor to left like I want.
In textBox works only second action which exactly I want. In richTextBox work both of them.
e.Handled = true; code should make a backspace key action not allowed.
Why is that?
I need this action in my richTextBox to validate text which I enter to this.
|
|
|
|