I have a Form with a TextBox in it. Every time the text changes i use the TextChanged Event to create a PDF-file and load it to an AxAcroPDF-Object in the same Form. This works fine, but then the TextBox loses focus and for some reason the textBox.Focus() after loading the file doesn't work.
Has anyone ideas how I can arrange that you can go on typing while refreshing the PDF?
EDIT:
i had another idea, i made a separate thread where i update the PDF and in the TextChanged-event i only set a flag. But now im getting a strange error
Unable to cast COM object of type 'System.__ComObject' to interface type 'AcroPDFLib.IAcroAXDocShim'.
Try this one:
textBox.Select();
textBox.Focus();
Im so ashamed of myself, i found a really, really dirty hack, but it works...
I did the following:
When i write a text in the MessageBox i rewrite my PDF in the TextChange-Event. In the same method i store the Control that has focus (when calling the LoadFile on the PDF-Object this Control still loses focus). And now the dirty work comes: I implemented a Thread that constantly sets focus to the Control stored in the variable. In the Leave-Event of the TextBox i reset the variable so other controls wont be blocked.
Its a really dirty hack i know, but now i can instantly "edit" a pdf with my own form, which is a nice eyecandy ;)
Thanks for all the help!
I could not get .Focus() and .Select() to work so I used Jquery and it works perfectly.
$(document).ready(function () {
setTimeout(function () {
$(".contentWrapper input")[0].focus();
}, 100);
});
Related
Sorry for asking such a basic question, but I just can't figure it out. I'm trying to display a status window that just says "Uninstalling prior versions" while the program runs so the user has some idea what's going on. So I created a C# form, added a label and do a window.show(). Here's what the form looks like in design mode:
And yet here's what displays:
I added a second label and a button to make sure that the text of my label wasn't some odd color or something that was causing the problem and they don't appear either.
What's going on here? This should be so simple. I've done this hundreds of times and never seen this behavior.
TaW said in this comment:
You can call Refresh() before starting the long-running work.
Refresh() was just what I needed!
My project is essentially a web page with a menu and an updatepanel. The user selects a choice from the menu, and a usercontrol is loaded into the updatepanel. I would prefer not to use an update panel, but, there are multiple databound controls that contain information that will then change the contents of another databound control. Anyways, my project calls for a message box to appear on the screen, which I have no issue in getting to work:
string s= "<script>alert('HayGuise');</script>";
ScriptManager.RegisterClientScriptBlock(c.Page, c.Page.GetType(), GUID.NewGUID().ToString(),s,false);
Now, I've tried a number of different tactics, including replacing GUID with a static string; I've used RegisterStartupScript, etc. My issue is that the message box does not show on the first click of the call button AFTER the updatepanel has updated to show a new usercontrol. But, if I click the button again, everything is great. If this is done on the very first form loaded into the updatepanel (opening up the site and selecting from the menu), everything works fine; it is only when the updatepanel updates again with a new form, that this will occur, and again, only on the first click.
Additionally, the code is being fired, and all code that follows the ScriptManager code fires, but the message box will not show until the button is clicked again. As I am testing this behavior at the moment, I've added the popup code to each of the buttons on the form, and the behavior is the same with each of them. It sucks that its taken so long to implement a reliable piece of code (for the messagebox) only to have this slight issue, and this is after I just figured out why my button events were firing twice on a single click. I pretty sure that it's going to be something simple, some sort of property that I'm not familiar with that needs to be set correctly. Damn, I'd love to just be able to settle all these little issues so I can proceed with the rest of the project. Sooooo close. Thank you for any help.
Edit: Additionally, the buttons are located in another usercontrol that is added to the usercontrol form that is shown in the updatepanel.
Edit II:
Thanks for your input, I apologize for getting back to this so late, I moved on to other parts of the project and just came back to this. The issue is not the startupscript method, nor the clientscriptblck method; the issue resides in the loss of value/viewstate/clientid's on postback.
At the time I posted this question, this project was a single page application. I tested functionality by creating a multipage application, and just kept going from there, vowing to come back to this issue. Well, I'm back and the issue does not reside in the update panel, it has something to do with my code, as I clear out the update panel (tried with a regular panel as well) and then reload the new usercontrol. When cleared, something goes haywire, and nothing fires on the first postback. Its a weird issue, that I have yet to find much (a couple articles) information on that is specific to just the first postback causing this issue. I'll update with an answer if I ever find one; the only fix I've found is to add a line to the menu select code, Server.Transfer(thecurrentpage), essentially refreshing the page. This solves all of the issues, but it seems a bit in poor taste. Thanks again for your input.
If you are working with AJAX UpdatePanel, following code should work for you. In my case, I was using update panel and none of the about worked except this one.
ScriptManager.RegisterStartupScript(myUpdatePanelID, myUpdatePanelID.GetType(), "myFunction", "myFunction();", true);
If you are using update panel in your page then the following code should work for you. You should use the RegisterStartupScript in the whole page using "this".ScriptManager.RegisterStartupScript(this, this.GetType(), "myFunction", "myFunction();", true);
I want to disable "bold" toggle button in an Excel sheet.
How can I do it?
I have the following code but it's not working:
CommandBarControl test = excel1.Application.CommandBars["Formatting"].FindControl(Id:113,Recursive:true);
if (test.Enabled)
{
MessageBox.Show(test.Caption + " enabled");
test.Visible = false;
test.Enabled = false;
}
I think it's not working because from Office 2007 they are using Ribbon Controls.
Can anyone help how to get the control of a specific button? So that I can change it's properties, enable/disable it by default, etc.
I'm afraid the answer is indeed that it isn't possible.
I've been looking at possibilities with class modules, because I thought that using a class, you could intercept the event that changes text to bold and then cancel that event. However, everything I could find was related to other events (value changes, calculation, workbook structure changes etc).
Even if it would work though, it would involve some serious coding and be error prone.
Maybe you're going at it the wrong way - what's the reason you remove this button? Probably there's another solution to your problem.
And as mentioned before, removing the button doesn't block the possibility to use ctrl+B or to paste bold text - you simply can't prevent this.
Not the answer you want, I'm sure, but I'm afraid this cannot be done.
I have a WinForms application that, at some point, will do some calculations that take a couple of seconds. During this time, I disable the controls. Additionally I want to display a popup that kind of 'blocks' the application more visibly.
I tried placing a Panel on top of the Form in order to do so, but there I'm somehow not able to add any text to it. I.e. the Labels and ImageBoxes I put there are somehow not displayed or behind the Panel.
Any suggestions how I could achieve this in a quick and easy way? .. I mean, without redesigning the whole Form.
Your problem with the things not showing up in your additional panel is that everything is happening in the same thread, but your calculations are blocking everything from appearing because they are hogging up the thread. You should look into using a backgroundWorker, which is one of the tools in WinForms. You should throw the function call that performs the calculations into the DoWork method of the backgroundWorker, then the form itself can continue to function during the calculations.
See http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx for examples
Create a Dialog Box (windows form) to popup during the processing, then you can have the Dialog Box close once your processing is completed.
By using a Dialog Box not a Message Box, you can still have control over closing the window when your processing is done.
You could create a simple UserControl with just a Label and an ImageBox, maybe with public setter for their values. You can add it to your form setting its Visible property to false. Then you can make it visible during your calculations and go back top invisible in the end.
Simplifying
I have a text box and a button
The button just create an messagebox with the text from the textbox.
But i change the value of the textbox, the new value apears (Ex: Type 123) but the message box does not show the value.
If i try to use the value in the programming (get the value by textbox1.text) the variable has nothing ( textbox1.text = "") but i can still see what i typed in the form.
Anyone has any clue?
Your button's click event handler should look something like this
private void button_Click(object sender, EventArgs e)
{
MessageBox.Show(textBox.Text);
}
I suspect you already have code similar to this and that at some point the textbox is cleared or otherwise set to String.Emppty but without seeing actual code it is difficult to help you
When/where did you check the value of textBox1.Text? If you're checking it in the constructor, Form1_Load, or anything else that occurs before you'll have typed text, you will get an empty value.
To properly check the value of textBox1.Text, you should set what's called a breakpoint on the line that calls MessageBox.Show(textBox1.Text). To do this, click in the grey area of the source editor (it's on the far left) on the line containing MessageBox.Show(..). A red circle will appear and your code should be highlighted. When you run your application and click on your button, your application should pause and Visual Studio will highlight that line and from here you can hover over "textBox1.Text" in the MessageBox.Show() line and it should show you the current value.
If your application is as simple as a form, a textbox, and your button1_Clicked event handling code, this should work no problem. If it is not this simple, then you need to look for anything that sets the value of the textBox in your code and make sure it isn't passing any blank values by using breakpoints.
To solve this properly, though, we really need more information.
Thanks Eric and Crippledsmurf. As both of you said, its hard to help without the code.
The problem I found is that when calling the form, I send some objects by reference, so I can track them down and I found that when (don't ask me why it happens that way, I'm still working on it) the construtor is called he make an new component, so the component in the interface no longer represents the one pointed by the variable "textbox1" (Yes Crash893, I haven't mispelled the name).
I found that I was making some mess with the references, and probably that was causing the problem. I fixed the problem by changing the actions performed by references for delegates and events, but I couldn't track down the exactly source of the problem.
Thanks, again, everyone for the insights.