How to capture Mouse clicks and Keystrokes in a VB app

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need to build a very simple text editor. The requirement is that
the input screen should be divided into 'm*n' cells ('m' rows, 'n'
columns, with each cell of a fixed size). Whenever the user wants to
input text, he will click on one of these cells, and then enter the
text. The text should then be visible inside the cell.

From my very limited knowledge of VB, I plan to use the 'group box'
construct to denote one cell. Now, here is where I need your help.

1. How do I create 'm*n' 'group boxes' on the fly (some kind of a
nested for loop ?)

2. How do I know when a user has clicked on a 'group box' ?

3. For every 'group box', I need to allocate a buffer to store the
characters that the user has entered for that particular cell. How
can this be done ?

Thanks.
 
Hello,

I need to build a very simple text editor. The requirement is that
the input screen should be divided into 'm*n' cells ('m' rows, 'n'
columns, with each cell of a fixed size). Whenever the user wants to
input text, he will click on one of these cells, and then enter the
text. The text should then be visible inside the cell.

From my very limited knowledge of VB, I plan to use the 'group box'
construct to denote one cell. Now, here is where I need your help.

A group box is for "grouping" related controls in a pretty frame. It
doesn't provide any support for text input. I think you want a textbox.
Or, if you want a "grid" of cells, use the DataGridView (.NET 2.0 only).
1. How do I create 'm*n' 'group boxes' on the fly (some kind of a
nested for loop ?)

Yeah, a nested for loop would work:

for x = 1 to m
for y = 1 to n
dim tb as TextBox = New TextBox()
tb.Location = new Point(20*x, 30*y)
tb.Size = new Size(20,30)
Me.Controls.Add(tb)
next y
next x
2. How do I know when a user has clicked on a 'group box' ?

The groupbox doesn't support a "clicked" event since it's just a
container control. If you had a textbox, capture the "Click" event.
3. For every 'group box', I need to allocate a buffer to store the
characters that the user has entered for that particular cell. How
can this be done ?

Just use a textbox and let the control hold on to the text. :)
 
Thanks for the reply. Based on it, I have the following question.

Patrick Steele said:
A group box is for "grouping" related controls in a pretty frame. It
doesn't provide any support for text input. I think you want a textbox.
Or, if you want a "grid" of cells, use the DataGridView (.NET 2.0 only).

I need to write my own text handling controls. That's because I am
designing this editor to input text that can come in any combination. For
example, when the user types 'a', followed by a '/', followed by a 'b', my
editor should display it as 'a' sitting vertically above 'b'. I think the
Microsoft GDI routine DrawString() can be used to do this. So, basically for
each cell I will have to store a sequence of tuples of the form <x,y,c> where
x and y are the coordinates of the point, and c is the character at that
point. A text box might not support this kind of a feature. If the
'groupbox' control does not allow me to capture keyboard/mouse interrupts
then what do I use. Is there any control which would offer me this free form
writing anywhere within a given cell.
 
Back
Top