|
I have a problem with a usercontrol that does not get focused or something after
leavning the usercontrol. Using the analogy with the document outline the setup is
as follows:
WinForm
- TableLayoutPanel (with 2 rows)
------> UserControl
----------> TextBox
----------> Button (Hello world, this just shows a hello world messagebox)
------> FlowLayoutPanel
----------> Button (OK)
----------> Button (Cancel, shows a messagebox asking whether to cancel)
Now, in the textbox_validating event i check if the text is a numeric value and if
it is not i set the e.Cancel property to true. This prevents clicking on "Hello
world"-button above. However, I've set the CausesValidation property on the
Cancel-button to false since I want the user to be able to cancel the operation
even if the Textbox doesn't contain a numeric value. Now, consider this scenario:
1. Click the "Hello world" button, a mesage box shows, nothing strange here
2. Enter "abc" in the Textbox and click the "Hello world" button, no messagebox
is shown since the TextBox doesn't contain a valid numerical value.
3. Click the Cancelbutton, a messagebox appears asking whether to cancel. Answer
No here just cancels the Cancel-messagebox.
4. Fix the error in the Textbox by entering a numerical value.
5. Click on the "Hello world" button, nothing happens!!!
Here I would expect a Hello world message box but I don't get any! I get mouse_enter, and mouse_down on the Hello world button but I don't get mouse_clicked. However, and this is weird, if I press the Cancel-button, don't need to click on it, just give it a mouse_down and then click on the Hello world button, the Hello world messagebox is shown and everything works well again. What is going on here? If I move the OK, Cancel to the usercontrol it all works well but it is not an option since the OK and Cancel belongs to a surrounding framework. Anyone experienced anything like this? Any help would be much appreciated.
Thanx, Ollie
|
|
|
|
|
I want to know about RTCP Packet in .net
how can i make RTCP packet and send it to other participent of session?
I know about RTCP packet format but I dont know how to implement it?
Thanks in advance.
Saurabh Patel
|
|
|
|
|
Hi to all.
First of all, my apologies to the moderators in case this is the wrong place to post my question.
I would like to know if it is possible to implement the following:
I have a winform that will, by clicking a button, launch a specific Excel File. The user will be able to edit it and by clicking another button, the Excel file will be saved (without any other kind of prompting from the user) and Excel will be closed.
Step1: launch Excel by clicking a button
Step2: user clicks another button on the winform and that will save the Excel file and close Excel.
Now, from what I've seen so far, I can achieve the first step. My problem seems to be in the second step. I have no idea on how I can save the work the user has done on the Excel File without having to Save first in Excel.
For instance, if my Excel File is this:
A1 cell = 1234
And after the launch I change it to this:
A1 cell = 12345
If I try to save to another file by clicking the other button on the winform that file will have:
A1 cell = 1234
How can I achieve what I want?
This is the code on the launch button:
private void button1_Click(object sender, EventArgs e)
{
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
ApplicationClass excelApp = new ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook myWorkBook = excelApp.Workbooks.Open("D:\\Teste.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)myWorkBook.Sheets["Sheet1"];
excelApp.Visible = true;
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
}
This is the code for the save button:
private void button3_Click(object sender, EventArgs e)
{
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Microsoft.Office.Interop.Excel.ApplicationClass excelApp = new ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook myWorkBook = excelApp.Workbooks.Open("D:\\Test.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)myWorkBook.Sheets["Sheet1"];
excelApp.Save("D:\\Test1.xls");
excelApp.Quit();
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
}
I have also tried this code:
private void button3_Click(object sender, EventArgs e)
{
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Microsoft.Office.Interop.Excel.ApplicationClass excelApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application") as Microsoft.Office.Interop.Excel.ApplicationClass;
Microsoft.Office.Interop.Excel.Workbook myWorkBook = excelApp.Workbooks[1];
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)myWorkBook.Sheets["Sheet1"];
Microsoft.Office.Interop.Excel.Range dataRange = (Microsoft.Office.Interop.Excel.Range)mySheet.Cells["1", "A"];
excelApp.Save("D:\\Test2.xls");
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
}
However, when I try this code, I end up with this exception:
System.Runtime.InteropServices.COMException was unhandled
Message="Exception from HRESULT: 0x800A03EC"
Source="Microsoft.Office.Interop.Excel"
ErrorCode=-2146827284
StackTrace:
at Microsoft.Office.Interop.Excel.ApplicationClass.Save(Object Filename)
Is it possible, what I want to achieve? Being able to save programatically from my winform an edited Excel file? If so, what am I doing wrong?
I would apreciate if anibody could point me to the right direction.
Thanks in advance
|
|
|
|
|
It seems to me that the following changes to your code should do the trick:
1) Declare myWorkbook as a class-level variable (as opposed to placing the declaration inside the event handlers
2) Use myWorkbook.SaveAs({new xls file name}, lots of missing values..)
Hope this is still helping (2 months after you posted this questions...),
Rolf
|
|
|
|
|
I am using the following Text/StreamWriter process to write to a Text file:
{
TextWriter tr=new StreamWriter("C:/Streamfile.txt");
tr.WriteLine("This line has been written by the StreamWriter process");
tr.Close();
}
However, if I want to write to a VBScript file or a Jscript file, then what manipulation will I have to do to the above code, such that I am able to write to those script files? Please help me guys.
Thank you,
Rajdeep.NET
modified on Tuesday, April 7, 2009 2:38 PM
|
|
|
|
|
i think you must select file encoding
utf8 or utf32
|
|
|
|
|
What? How will I select file encoding utf8 or utf32? help
|
|
|
|
|
If I have understood you correctly, you want to generate a VBscript or Jscript file from within your C# app. All you have to do is write the contenst of the fiel exactly like you would in notepad or whatever. You would probably want to change the file extension (to .vbs for the VBScript file), but thats all, there is nothing special about it.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Try using this code:
private void btnSave_Click(object sender, EventArgs e)
{
FileDialog salvareFisier = new SaveFileDialog();
salvareFisier.Filter = "Text files (*.txt)|*.txt";
if (salvareFisier.ShowDialog() == DialogResult.OK)
{
FileStream fisier = new FileStream(salvareFisier.FileName, FileMode.Create, FileAccess.Write);
addText(fisier,"your _text _ here ");
addText(fisier, "\r\n");
fisier.Close();
}
else
MessageBox.Show("Data has not been saved");
}
public static void addText(FileStream f, string valoare)
{
byte[] info = UTF8Encoding.Default.GetBytes(valoare);
f.Write(info, 0, info.Length);
}
Regards,
Alex
|
|
|
|
|
hi every one
how to add control to gridcontrol with syncfusion
|
|
|
|
|
You should ask your question in the SyncFusion forums.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Hola gente, como andan?...
Tengo un gran inconveniente y en ningún lado puedo encontrar la respuesta. A ver si me ayudan.
Necesito crear una búsqueda de Pacientes que se encuentran en un Datagridview. Como lo puedo hacer?. Estoy trabajando con C# en .NET.
Dejo una imagen del formulario que estoy usando para tal fin: http://img21.imageshack.us/img21/9820/buscars.png
Espero que alguien pueda ayudarme.
|
|
|
|
|
This is an English speaking site.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hola Hola Jingalala Jingalala Twinkle twinkle little star Hola Gente mente tente lingrie! How's that ?
|
|
|
|
|
Why you don't search for filter proeprties of Datagridview.
Check this.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I have just started working in c# so I'm not that familiar with it. Still, I need to build a paint program and I am a bit stuck at Flood Fill. I want to be able to fill areas with an undetermined shape, so I used the SetPixel command, but it sets only one pixel (I'm not entirely sure of this).
For now, I try to change the color from white to one I pick myself. I call the function in the MouseDown function, and I think it should work.
Please help!
bmp = new Bitmap(pictureBox1.Width,pictureBox1.Height);
private void FloodFill(int x, int y)
{
bmp.SetPixel(x, y, DrawColor); //sets the color of the pixel to DrawColor I picked
pictureBox1.Image = bmp; // assigns the bitmap to the picture box; I work with it to be ale to save the picture
if (bmp.GetPixel(x + 1, y) == Color.White) //all four search for each white pixel
FloodFill(x + 1, y);
if (bmp.GetPixel(x, y + 1) == Color.White)
FloodFill(x, y + 1);
if (bmp.GetPixel(x - 1, y) == Color.White)
FloodFill(x - 1, y);
if (bmp.GetPixel(x, y - 1) == Color.White)
FloodFill(x, y - 1);
return;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
startPoint.X = e.X;
startPoint.Y = e.Y;
FloodFill(e.X, e.Y);
pictureBox1.Image = bmp;
drag = true;
}
|
|
|
|
|
You will have to setup a loop so that more than one pixel is changed.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
You should not be setting the picture in the picture box inside your recursive function. There's also flood fill methods in GDI, perhaps you can p/invoke one of them ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
k_crysa wrote: I want to be able to fill areas with an undetermined shape
As for "undetermined shape", do you have access to the points used to define/enclose the region? If so, you may be able to use the System.Drawing.Drawing2D.GraphicsPath [^] or System.Drawing.Region[^] classes to fill your area. At the bottom of each of these pages is a link to "Members" of each class, so you can see the functions and properties available. I seem to remember there being a simple "Fill()" function, but can't find the reference to it right now. For performance reasons, it's usually best to avoid setting individual pixels if at all possible.
I could be wrong, I may be thinking of the FillMode, which might be different that what you're looking for. Anyone know if I'm on the right track here?
Hope this helps
Dybs
|
|
|
|
|
Hy Guys,
I am trying to do my first c# project. Its a calculator like the one windows has. I still have a long way to go and i was looking for some pointers , tips that you may suggest.
Please find the whole project by following the lok below.
http://freestorage.ro/calculator_visual.rar
Regards,
Alex
|
|
|
|
|
al3xutzu00 wrote: I still have a long way to go and i was looking for some pointers , tips that you may suggest.
What are they ? BTW I doubt that nobody gonna download the link you posted. You better ask questions instead of showing what you've developed...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi,
I have a basice question.
Im showing some data in datagridview control. One of the columns is of the type combobox.
When populating this combobx with data, i want that the first item is selected.
How can i do that?
Thanks.
|
|
|
|
|
Hi,
After you have initialized the combo box with values try using this :
[combo_box_name].SelectedItem = [value]; .
(without the brackets)
It works for me. Is this what you were asking?
Regards,
Alex
|
|
|
|
|
Combobox.SelectedIndex = 0; is more accurate. As well as check if Combobox have items. eg
if(Combobox.Items.Count != 0)
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I'm sure the title is confusing, but here's what I'm trying to do: I have a process that I create using the System.Diagnostics.Process class, and I want the memory the application uses to be read-only to all external applications except mine, that starts the process.
Does anyone know of a way to do this?
|
|
|
|
|