-
November 9th, 2011, 09:58 PM
#1
Format Textbox?
Hello everybody, I am trying to make a textbox look "nicely formatted". I ask the user for their name, and their Date of birth (separated by "tab"). I am separating the inputs by a newline. What's happening is if somebody's name is much longer than somebody else's, the tabbing becomes different between the two inputs, thus making the textbox look unorganized. Any ideas of how I can assign coordinate positions for each variable, or any other ideas ? Thanks for your help in advance!
-
November 10th, 2011, 02:57 AM
#2
Re: Format Textbox?
You should use a ListBox, ListView or DataGridview for this kind of thing, the textbox in itself isn't geared towards this kind of formatting.
It's not a bug, it's a feature!
-
November 10th, 2011, 08:14 AM
#3
Re: Format Textbox?
If you must use a text box then you can use a non porportional font and padd with spaces up to x characters which will allow you to aline the columns as needed but as foamy says those other controls are better suited for this type of thing.
Always use [code][/code] tags when posting code.
-
November 10th, 2011, 08:47 PM
#4
Re: Format Textbox?
Thanks everybody, I ended up using a listbox. Im not sure if I should start a new thread, but I have another question.. What is the easiest way to do the following:
1- Open an Excel sheet
2- Search for the cell containing "N/A".
3- return the values of Cells A:H in the row where "N/A" was found.
I already have code to open the Excel sheet, but any help on step 2-3 would be greatly appreciated!
-
November 11th, 2011, 02:58 AM
#5
Re: Format Textbox?
Show us the code you have, and maybe we'll be able to fill in the blanks
It's not a bug, it's a feature!
-
November 11th, 2011, 03:11 AM
#6
Re: Format Textbox?
Oright, I will clarify my goal and give my code :
I am trying to check if the excel file exists. If it does, try to find the last nonnull cell and "append" to the file with new data. If it doesnt, create it then append. Sounds simple, but the Excel Com object is giving me headaches .
Code:
private void button11_Click(object sender, EventArgs e)
{
Excel.Application oXL;
Excel.Workbook oWB;
Excel.Worksheet oSheet;
Excel.Range oRng;
string curFile = @"file" + month + ".xlsx";
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = false;
if (File.Exists(curFile) == false)
{
//Get a new workbook.
oWB = (oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel.Worksheet)oWB.ActiveSheet;
//Add table headers going cell by cell.
oSheet.Cells[1, 1] = "1";
oSheet.Cells[1, 2] = "2";
oSheet.Cells[1, 3] = "3";
oSheet.Cells[1, 4] = "Date";
oSheet.Cells[1, 5] = "Time In";
oSheet.Cells[1, 6] = "4";
oSheet.Cells[1, 7] = "Time Out";
oSheet.Cells[1, 8] = "5";
oSheet.Cells[1, 9] = "Notes";
oSheet.get_Range("A1", "I1").VerticalAlignment =
Excel.XlVAlign.xlVAlignCenter;
}
else if (File.Exists(curFile) == true)
{
oWB = oXL.Workbooks.Open(curFile, 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);
oSheet = (Excel.Worksheet)oWB.ActiveSheet;
// Create an array to multiple values at once.
string[,] saNames = new string[6, 6];
saNames[0, 0] = guestinexcel + " " + phonenumber;
saNames[0, 1] = residentinexcel;
saNames[0, 2] = roominexcel;
saNames[0, 3] = date;
saNames[0, 4] = timein;
saNames[0, 5] = emp.
int rowIndex = 1; int colIndex = 1;
while (oSheet.get_Range("A" + rowIndex, "H" + colIndex).ToString() != null)
rowIndex += rowIndex;
oSheet.get_Range(lastCell, "H2").Value2 = saNames;
//AutoFit columns A:D.
oRng = oSheet.get_Range("A" + rowIndex, "H" + colIndex);
oRng.EntireColumn.AutoFit();
oXL.Visible = false;
oXL.UserControl = false;
string path = curFile;
oSheet = null;
oRng = null;
oWB.SaveAs(path, Excel.XlFileFormat.xlWorkbookDefault,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Excel.XlSaveAsAccessMode.xlExclusive,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
oWB = null;
oXL.Quit();
// Clean up
// NOTE: When in release mode, this does the trick
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
Last edited by richard_chaaya2; November 11th, 2011 at 04:14 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|