|
Ah, ok...I misunderstood what you were asking. See the code below that creates the line numbers in textbox1:
Here's the code that does the work:
private void updateNumberList()
{
Point pos = new Point(0, 0);
int firstIndex = richTextBox1.GetCharIndexFromPosition(pos);
int firstLine = richTextBox1.GetLineFromCharIndex(firstIndex);
pos.X = ClientRectangle.Width;
pos.Y = ClientRectangle.Height;
int lastIndex = richTextBox1.GetCharIndexFromPosition(pos);
int lastLine = richTextBox1.GetLineFromCharIndex(lastIndex);
pos = textBox1.GetPositionFromCharIndex(lastIndex);
textBox1.Text = "";
for (int i = firstLine; i <= lastLine; i++)
{
textBox1.Text += i + 1 + " \r\n";
}
}
Here's the code that calls it:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
updateNumberList();
}
|
|
|
|
|
OK - the problem is probably to do with GetCharIndexFromPosition. I don't see why you're doing that. You should be able to get the index from the cursor position, which is retrieved from the selection start property. If you step through the code when you step back, you should see which line is not giving the value you'd hope, but I do think that's the way to get the correct index, all the time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Instead of scrolling the textbox, find the number of the first visible line in the richtextbox.Say if it is 15 and the text box can show only 'n' numbers,
textBox1.text="";
for i=15 to 15+n
textBox1.Text+=i+"\n";
Regards,
Arun Kumar.A
|
|
|
|
|
Hi!
I'm not sure if I understand correctly what you try to achieve, but there a quite useful article about line numbers for the RichTextBox[^] here on CP.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I'm trying to write an app which will backup the contents of a USB
stick.
I want the setting screen to give the user the option to select
the types of files to backup.
Is there a way to say select only files of type text
without hardcoding the various extexsions like .txt .doc etc
Am i clear ?
Thanks
|
|
|
|
|
You can use File.GetFileExtension to get the extension of a filename that was selected. You can take any string you want and iterate over the files in a folder, looking for that extension.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi thanks for the reply.
That's what i'm doing now.
I'm using this:
<br />
DirectoryInfo dir = new DirectoryInfo(drive_letter);<br />
fi = dir.GetFiles();<br />
foreach (FileInfo f in fi)<br />
{<br />
if (f.Extension == ".txt") <br />
f.CopyTo(sBackupLocation + "\\" + f.Name); <br />
}<br />
But the way i see it is; if i want to add another type of 'textproccessing' file
such as .doc then i'd have to add an extra condition in the IF statement to include
this extension.
I was thinking of giving the user the option between broad catagories of file like:
'picture files' - encapsulating .jpeg, .bmp, .tif, .gif and so on.
i just thought there would be a more simple way that having to include all the various extensions.
Thanks again
|
|
|
|
|
Don't forget to do ToLower on f.Extension, so it's not .TXT. And, the change to make, is to have a collection of extensions and then do extensions.Contains(f.Extension). You can then dynamically add all you want to.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
you can try to recognize text files like this:
- read the first few hundred bytes;
- first assume it might be 16-bit characters as in Unicode; UTF8 and UTF16 encoded
files start with particular byte values.
- if not, assume it might be 8-bit characters and check the first bytes for
non-printable chars (mainly zero).
You may want to exclude some files you consider text but not source, typically
because they are output files from a program you could run again
(e.g. a cross-compiler listing, maybe a big log file, ...).
Such exclusion could be extension based.
|
|
|
|
|
*grin* I think you misunderstood the question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
No I dont think so, in backup applications it is important to copy all source files;
buying/downloading a new app that uses new extensions is fine, as long as you dont
forget to add the new extensions to the backup utility, unless it recognizes
texts all by itself...
Of course for non-text files, it does not help. From a later post the OP wanted to recognize all kinds of images without using the extension; for this I have no solution whatsoever. Do you ?
|
|
|
|
|
No, I don't see any way he can automatically find them without *ever* specifying the extensions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hey All,
Thanks for the suggestions (especially the ToLower one, i would have def. forgotten that one).
I guess it looks like i'm gonna be coding them in myself then. I was thinking along the lines of the windows file search dialog in which you can select the broard reanges of file types. Oh well.
Thanks again.
|
|
|
|
|
i am using picturebox to create visual buttons, but i want the picturebox has tabstop property, how can i do?
|
|
|
|
|
Use a button and set it's image to be the image you want to show.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i am creating button that has some special properties, like zoom, rounded, gradient etc. properties. and also i am creating textbox, checkbox... controls from picturebox, and i want to know how can i catch [tab] key into my new control to focus, any api code?
|
|
|
|
|
The below code just provides the ability to change the password:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<asp:ChangePassword ID="ChangePassword1" runat="server"
CancelButtonType="Button"
ChangePasswordButtonType="Button"
ContinueButtonType="Button"> </asp:ChangePassword>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I want to give the user the capability to make almost a full update of his
personal account details which, besides the password, would also
include First Name, Last Name, Email, Adress, City, Country, Zip and
Phone.
Can it be done by including the “ChangePassword” control or it needs
to be done completely in a programmatic way ?
If so what code should I use ?
( I am using C# and Asp.net 2.0 )
|
|
|
|
|
Hey guys,
I'm trying to check the uniqueness of the index key of visual foxpro tables. From the tableinfo table I read all names of the tables in the database and the name of their index key.
The name, index key and path (omniwinroot) are stored in an instance of class ActiveTable named tableToAnalyze
Next I invoke a member method of ActiveTable (Analyze.Table) on that instance.
This executes 2 queries on the table. The first one counts all the records, last one counts only those with distinct index key.
If there are less unique index keys then there are rows in the table then the UNunique index keys are safed in a queue (so it could be fixed later).
The goal is to copy (by value) tableToAnalyze to a list of instances of ActiveTable when double index keys were found.
So something like this:
<br />
Class classVar = new Class();<br />
list<Class> classList= new List<Class>();<br />
<br />
classVar.integer1 = 1;<br />
classVar.integer2 = 3;<br />
<br />
if (condition) classList.Add(classVar);<br />
From there i could display in a datagridview and prompt the user to repair (only those tables he wants to repair).
The code I have seems to copy by reference. After all the tables are analyzed my list holds 2 (which is correct) of the same values. Both hold the values of the last table
What am i doing wrong?
private void dubbelNummeringToolStripMenuItem_Click(object sender, EventArgs e)<br />
{ <br />
string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY ctablename";<br />
string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf";<br />
<br />
OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo);<br />
<br />
ActiveTable tableToAnalyze = new ActiveTable();<br />
List<ActiveTable> tableToAnalyzeList = new List<ActiveTable>();<br />
<br />
using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
{<br />
try<br />
{<br />
ConnTableInfo.Open();<br />
commandTableInfo.Connection = ConnTableInfo;<br />
OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (readerTableInfo.Read())<br />
{<br />
tableToAnalyze.omniwinRoot = omniwinRoot;<br />
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
tableToAnalyze.AnalyzeTable();<br />
tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;<br />
if (tableToAnalyze.verschil > 0)<br />
{<br />
tableToAnalyzeList.Add(tableToAnalyze);<br />
}<br />
<br />
}<br />
ConnTableInfo.Close();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
public class ActiveTable<br />
{<br />
public string omniwinRoot;<br />
public string table;<br />
public string tableKey;<br />
public int tableRecords;<br />
public int tableUniqueRecords;<br />
public int verschil;<br />
Queue<string> doubleKey = new Queue<string>();<br />
<br />
public void AnalyzeTable()
{<br />
string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\dpatient.dbc";<br />
string queryNumberRows = "SELECT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) " + "ORDER BY " + tableKey;<br />
string queryDistinctRows = "SELECT DISTINCT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) " + " ORDER BY " + tableKey;<br />
string queryGetNotDistinctId = "SELECT " + tableKey + ", count(*) AS count FROM " + table + " GROUP BY " + tableKey + " HAVING count > 1";<br />
try<br />
{<br />
OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
OleDbCommand command = new OleDbCommand(queryNumberRows);<br />
command.Connection = ConnDpatient;<br />
ConnDpatient.Open();<br />
<br />
tableRecords = command.ExecuteNonQuery();<br />
<br />
command.CommandText = queryDistinctRows;<br />
tableUniqueRecords = command.ExecuteNonQuery();<br />
if (tableRecords - tableUniqueRecords > 0)<br />
{<br />
command.CommandText = queryGetNotDistinctId;<br />
try<br />
{<br />
OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (reader.Read())<br />
{<br />
doubleKey.Enqueue(reader.GetString(0).Trim());<br />
}
|
|
|
|
|
Creating a new instance of the ActiveTable variable should do the trick into your while loop
while (readerTableInfo.Read())
{
tableToAnalyze = new AnalyzeTable();
tableToAnalyze.omniwinRoot = omniwinRoot;
tableToAnalyze.table = readerTableInfo.GetString(3).Trim();
tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();
tableToAnalyze.AnalyzeTable();
tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;
if (tableToAnalyze.verschil > 0)
{
tableToAnalyzeList.Add(tableToAnalyze);
}
}
|
|
|
|
|
That did the trick indeed.
I thought about it but couldn't understand why this would help.
Still don't, hoping to come across an answer in the coming days.
(studying c# for work)
Anyway, thanks a lot.
|
|
|
|
|
Because you were reassigning the properties of the same instance each time. Thats why you got the same object twice in your list because the object is by reference.
With the modification, you'll create a new instance of the object on each iteration and each object in your list will be different because they point at their own reference.
Hope that help
|
|
|
|
|
Yes, that helped
thanks
|
|
|
|
|
i have two forms ChatManagerForm and ChatWindowForm, and i have a bool variable in ChatManagerForm to indicate that the ChatWindowForm is opened or not.
i want to set this variable to false at ChatWindowForm closing, here i think about two choices.
first: make the variable static,and keep the ChatWindowForm refrence and then
access the variable from the ChatWindowFrom instance.
second: use delegetes and events(pass message from ChatWindowForm to ChatManagerForm).
what is the best, the most practical.
or any other suggestions.
thanks in advance
|
|
|
|
|
|
cant you just use myChatWindowForm.Visible ?
|
|
|
|