|
Message Removed
modified 20-Mar-14 10:11am.
|
|
|
|
|
Hi
how to use Response.Clear() in c#
|
|
|
|
|
Context?
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
I have a pivot table in excel sheet 1. I need to write a C# code to copy and paste whole pivot table in sheet 2 of same excel file. While copying, I need to expand all columns data also.
Please help me in doing this.
Thanks
|
|
|
|
|
rajnknit07 wrote: Please help me in doing this. Help with what exactly?
As is, you only specified what the finished solution should do. Divide your problem in smaller things, like reading an Excel file using C#, writing a file, and then move on to modifying data.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I would like to know what is the best way to manage the passage of events between WinForms.
I have to click on the MainForm 6 buttons with either the mouse or using 6 corresponding digital inputs.
Obviously with the mouse there are no problems, but to use the digital inputs as mouse-clicks, I have written a class that runs a background timer-thread that reads the digital inputs and uses delegates to notify the MainForm on the changes of the digital inputs (from 0 to 1) so that his handlers can perform the function:
key-x.PerformClick()
to call the method linked to the x button.
My problem is: how can I do it as fast, clean and safe using MainForm modal-forms childs ? And overall, what about with the children of the children that can be up to the 4-th level depth ? The 6 buttons have form by form always to perform different operations.
OK, I can use a chain of delegates among the various modal-form-childs but it is ugly and not so simple, fast and very safe to realize.
Any idea ?
modified 24-Mar-14 12:20pm.
|
|
|
|
|
What do you mean with a "digital input"? I'd assume you'd loop through your forms, and hook up any buttons using reflection.
Am I right that you want to see an event raised in the mainform when one of the buttons on the child-forms is clicked?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for the answer Eddy, I have 6 on/off digital-inputs pins on an electronic interface connected to the pc that 'clicks' the 6 buttons on the frames as a mouse. Pin 1 for button 1, . . . pin 6 for button 6 just like a mouse. The mainform received the 6 inputs 'buttons' states from a communicationInterface timer-thread that reads the input pins and I need to send these input states also to the last open child-form that many times it can be a child of a child of a child of the mainform.
|
|
|
|
|
Mario 56 wrote: The mainform received the 6 inputs 'buttons' states from a communicationInterface timer-thread that reads the input pins and I need to send these input states also to the last open child-form that many times it can be a
child of a child of a child of the mainform. So, there's never more than 6 buttons? Acting on one of the six buttons of the currently active form?
You don't need to send those states back and forth between the forms; put them in a separate class and share it between the forms.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No Eddy, I cannot simply share the inputs using a separate class, WinForm threads can be awakened only using events or with a timer loop to read the digital inputs in every opened child form. I have solved the problem using delegate:
public delegate void Key1();
public Key1 extKey1Delegate;
public delegate void Key2();
public Key2 extKey2Delegate;
public delegate void Key3();
public Key3 extKey3Delegate;
public delegate void Key4();
public Key4 extKey4Delegate;
public delegate void Key5();
public Key5 extKey5Delegate;
public delegate void Key6();
public Key6 extKey6Delegate;
public mainForm
{
extKey1Delegate = new Key1(Key1Method);
extKey2Delegate = new Key2(Key2Method);
extKey3Delegate = new Key3(Key3Method);
extKey4Delegate = new Key4(Key4Method);
extKey5Delegate = new Key5(Key5Method);
extKey6Delegate = new Key6(Key6Method);
}
and in the commInterface class that read the digital inputs:
_interfaceInputStatus = modbus.ReadInputs(1);
if (_interfaceInputStatus[(int)keyButtons.KEY1]) { extFormControl.Invoke(extFormControl.extKey1Delegate); }
if (_interfaceInputStatus[(int)keyButtons.KEY2]) { extFormControl.Invoke(extFormControl.extKey2Delegate); }
if (_interfaceInputStatus[(int)keyButtons.KEY3]) { extFormControl.Invoke(extFormControl.extKey3Delegate); }
if (_interfaceInputStatus[(int)keyButtons.KEY4]) { extFormControl.Invoke(extFormControl.extKey4Delegate); }
if (_interfaceInputStatus[(int)keyButtons.KEY5]) { extFormControl.Invoke(extFormControl.extKey5Delegate); }
if (_interfaceInputStatus[(int)keyButtons.KEY6]) { extFormControl.Invoke(extFormControl.extKey6Delegate); }
and in the mainForm class using them with the code:
private void key1_Click(object sender, EventArgs e)
{
. . . .
}
. . . . .
private void key6_Click(object sender, EventArgs e)
{
. . . .
}
void Key1Method()
{
if (mainFlag) key1.PerformClick();
else KeyCallback(1);
}
void Key2Method()
{
if (mainFlag) key2.PerformClick();
else KeyCallback(2);
}
void Key3Method()
{
if (mainFlag) key3.PerformClick();
else KeyCallback(3);
}
void Key4Method()
{
if (mainFlag) key4.PerformClick();
else KeyCallback(4);
}
void Key5Method()
{
if (mainFlag) key5.PerformClick();
else KeyCallback(5);
}
void Key6Method()
{
if (mainFlag) key6.PerformClick();
else KeyCallback(6);
}
and then every opened child subscribe the event to all its children. obviously exists a table where is specified which method of which class should serve the input event.
I would be glad if someone would tell me what is the method to know which is the form currently in use so maybe I can avoid to use the table. Every form is modal.
Thank you
|
|
|
|
|
Mario 56 wrote: I would be glad if someone would tell me what is the method to know which is the form currently in use Form.ActiveForm[^]
"Gets the currently active form for this application."
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
This sounds like a case when you really want a MVVM type separation of concerns. The model is whether the 6 items are 'on'; that can be affected by several things, not just the UI, so putting logic about them in the UI is wrong.
You don't actually need a VM if the model is simple enough to bind to the view, so I think what you need from a code perspective is: a model class which implements INotifyPropertyChanged so you can bind it:
class Input {
private bool on;
public bool On {
get { return on; }
set { on = value; Notify("On"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void Notify(string property) {
var handler = PropertyChanged;
if(null != handler) handler(this, new PropertyChangedEventArgs(property));
}
}
class DataModel {
public IList<Input> Inputs { get; private set; }
public DataModel() {
Inputs = new List<Input>();
for(int i = 0; i < 6; i++) Inputs.Add(new Input());
}
}
Your UI should be given the data model and data bind to it; let's imagine check boxes for the sake of simplicity, but you can use anything that has a boolean property you can bind to, including custom controls:
class MainForm : Form {
public MainForm(DataModel dataModel) {
InitializeComponent();
for(int i = 0; i < 6; i++) {
(CheckBox)(checkBoxGroup.Controls[i]).DataBindings.Add("Checked", dataModel.Inputs[i], "On");
}
}
}
If you have to poll the serial port to find out the real state of these things, then that's unfortunate but it's okay. Just set the On property of the Inputs in the data model (make sure it's the same instance!) and the UI should update.
Don't bind actions to the buttons being clicked. Instead, subscribe to the property notification changes from the inputs. (Or, probably better, have the data model do that and fire a custom event instead.)
|
|
|
|
|
Thanks Bob, your implementation of the processing of the digital inputs is really very efficient using notify. The 6 digital inputs (on/off) can only be on one at a time and they have to be treated as real push-buttons, and in fact, they have to simply replace the 6 push-buttons in the various forms (main and nested child forms) that are clicked with the mouse and are used when the enclosure that contains the pc is closed and then the 'push-buttons' should be operated by the 6 digital inputs instead of the mouse or push-screen. My main problem is how to communicate efficiently the status of the digital input to the opened child forms that can have also many levels of nesting. As you know the thread of a form sleep since it doesn't receive a winform event pushed in its dispatcher pump so I need the best and simple way to concatenate the series of event and relative delegate from child forms to main, but overall from main to childs and from main to children of the childs. The thread that reads the digital inputs is one and this communicate the state of the inputs to the mainForm.
|
|
|
|
|
You can data bind an instance of this Input class to multiple forms. Data binding to something which implements INPC will result in that control being updated when the event's fired.
I think I might have not understood what the 'inputs' are though. I thought you were reading the state of pins on a serial cable or something similar where on and off were both relevant; it seems like you actually want to fire the same handlers when they go to 'on' as when buttons are clicked, and 'off' doesn't matter.
In that case, you should put your processing code in a single place (you can call that class App or StateManager or Processor or other similarly generic things), and have the event handlers on your many forms do nothing except call methods on this central class. This is a classic 3 tier architecture (separation of view, logic and data), except that your data model is probably quite minimal. You can then attach event handlers to whatever mechanism you use to notify changes to the state of the external inputs, which call the same methods. If you need a UI cue to be reflected back to forms, use data binding to classes in the data model which implement INPC.
|
|
|
|
|
Thanks Bob, I wrote my application in perfect agreement with your general information and in fact the application now runs perfectly and quite fast. I get input from a digital serial interface that uses the Modbus protocol. My class that reads data from the bus is named CommInterface and it is the interface that sends data to the mainForm which then makes them available to all the other various children generating the appropriate events (6 of these are treated as mouse clicks on buttons to operate the forms). I have sent a small part of my code in one of my previous answers. Thanks so much for your kindness Bob and to all other peaple of code project. I have used for many years Visual C++ and now I'm switching to using C#, but this is not as easy as many would like to believe.
modified 24-Mar-14 4:36am.
|
|
|
|
|
Hi,
I want to convert HTML content to rtf format or save this html content as .rtf file . I already done this with the help of interop dll. But it will take large time for conversion , if we host it in a server. Is there any free dll for HTML to RTF conversion.Please help if anybody knows it..
Sample HTML Content..
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 12 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:serif;
panose-1 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:0in;
line-height:115%;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
.MsoPapDefault
{margin-bottom:10.0pt;
line-height:115%;}
<a href="/Members/page">@page</a> WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
-->
</style>
</head>
<body lang=EN-US>
<div class=WordSection1>
<div>
<div>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:0in;text-align:right;text-autospace:none'><span
style='font-size:54.0pt;line-height:115%;font-family:"serif","serif";
color:black'>TEST</span><span style='font-size:19.5pt;line-height:115%;
font-family:"serif","serif";color:black'> TEST CONTENT</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:0in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'> </span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>1. TEST CONTENT:</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>2.  TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>3. TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>4. TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>5. TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>6. TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:#FF9900'>8. TEST CONTENT.</span></p>
<p class=MsoNormal align=right style='margin-top:5.0pt;margin-right:0in;
margin-bottom:5.0pt;margin-left:.5in;text-align:right;text-autospace:none'><span
style='font-size:19.5pt;line-height:115%;font-family:"serif","serif";
color:red'>HELO</span></p>
</div>
</div>
</div>
</body>
</html>
Thanks in Advance
|
|
|
|
|
A free, non-interop version can be found here[^], but I don't think that it'll be faster. Another alternative is described in this[^] CodeProject article, using XSL. Third alternative comes from Microsoft and uses WPF[^].
If these three do not fit, then you could search for a webservice that offers this functionality; again, that's a slower option, as it means one has to transmit the data before on can transform it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Greetings,
I am looking for a way to transform, and in particular rotate, the entire picturebox and not just the image inside of it.
Ig you add a picture to a Word or Excel document the picture is inserted and has grips around it and a rotate handle at the top.
How can I replicate this in a c# windows form?
Thanks,
Ron Wensley
|
|
|
|
|
Rotating the image is quite easy.
Rotating the PictureBox control is a huge pain in the ass. Chances are REALLY good you don't even need the PictureBox control at all.
Stuff like this is easily done in WPF. Not very easy in WinForms.
|
|
|
|
|
Dave...I see that rotate controls in WPF is very easy. My problem is that I am way down the road in the WinForm app and it uses several custom controls that are not compatible with WPF.
|
|
|
|
|
You're better off skipping the PictureBox and just painting on the surface that's holding your stuff.
The reason being is you'd have to paint the PictureBox yourself anyway to get it to rotate, so skip it and just paint the rotated image.
The underlying Windows controls don't support being rotated.
|
|
|
|
|
I'm trying to capture the output of a Dell executable command, racadm.exe. I can go to the cmd prompt and type in "racadm.exe getsysinfo" and get an output, but when I try to do this programmatically, it is not working. I can also programmatically use the code block below to get a directory listing, but with this specific exe, I cannot capture the standardoutput.
Any ideas on what I'm doing wrong?
System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = "c:\\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "/c" + " racadm.exe" + " getsysinfo";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
string output = si.StandardOutput.ReadToEnd();
si.Close();
MessageBox.Show(output);
|
|
|
|
|
Try executing the process directly, rather than piping it through the command prompt.
si.StartInfo.FileName = "racadm.exe";
si.StartInfo.Arguments = "getsysinfo";
Also, you might want to wait for the process to exit before closing it:
si.Start();
si.WaitForExit();
string output = si.StandardOutput.ReadToEnd();
si.Close();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi, thanks for the reply.
I tried your suggestions and string output is empty, just as it is with the first code block?
Have you any other ideas?
|
|
|
|
|
Try using the full path to racadm.exe , rather than leaving cmd to find it.
|
|
|
|