Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Create Insert Table menu like in Word using TDrawGrid component Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
24-Jan-04
Category
Reporting /Printing
Language
Delphi 3.x
Views
210
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I think all of us know the function in MS Word which is called "Insert Table". 
Pressing this button there appears SubMenu window which is separated in squares - 
cells and columns. When we move a mouse on these squares they become active and 
after pressing left mouse button is create the table with the same number of cells 
and columns as we selected. Maybe anyone could suggest how to do this.

Answer:

The solution is

Put TDrawGrid component on Form and name it dwgTable, then property DefaultDrawing 
set to false.
Also configure the following properties:
DefaultColWidth to 20
DefaultRowHeight to 15
ColCount first set to 0 then 3
RowCount first set to 0 then 3
BorderStyle to bsNone
Schroolbar also to none

The code is
1   
2   procedure TForm1.dwgTableMouseMove(Sender: TObject; Shift: TShiftState; X,
3     Y: Integer);
4   var
5     vCol, vRow: Integer;
6   begin
7     if (X > 0) and (y > 0) then
8     begin
9       vCol := Trunc(x / (dwgTable.DefaultColWidth + 1));
10      vRow := Trunc(y / (dwgTable.DefaultRowHeight + 1));
11      dwgTable.ColCount := vCol + 2;
12      dwgTable.RowCount := vRow + 2;
13    end;
14    dwgTable.Height := (dwgTable.DefaultRowHeight + 1) * dwgTable.RowCount;
15    dwgTable.Width := (dwgTable.DefaultColWidth + 1) * dwgTable.ColCount;
16  end;
17  
18  procedure TForm1.dwgTableDrawCell(Sender: TObject; ACol, ARow: Integer;
19    Rect: TRect; State: TGridDrawState);
20  var
21    vColText, vRowText: string;
22    RowHorzOffset, RowVertOffset,
23      ColHorzOffset, ColVertOffset: integer;
24  begin
25    if (dwgTable.ColCount - 1 = ACol) or (dwgTable.RowCount - 1 = ARow) then
26    begin
27      dwgTable.Canvas.Brush.Color := clInfoBk;
28      dwgTable.Canvas.FillRect(Rect);
29      vColText := Inttostr(ACol + 1);
30      vRowText := Inttostr(ARow + 1);
31      with dwgTable.Canvas do
32      begin
33        RowVertOffset := (((Rect.Bottom - Rect.Top) - TextExtent(vRowText).CY)
34          div 2);
35        RowHorzOffset := ((Rect.Right - Rect.Left) - TextExtent(vRowText).CX)
36          div 2;
37        ColVertOffset := (((Rect.Bottom - Rect.Top) - TextExtent(vColText).CY)
38          div 2);
39        ColHorzOffset := ((Rect.Right - Rect.Left) - TextExtent(vColText).CX)
40          div 2;
41      end;
42  
43      if (dwgTable.ColCount - 1 <> ACol) or (dwgTable.RowCount - 1 <> ARow) then
44      begin
45        if (dwgTable.ColCount - 1 = ACol) then
46          dwgTable.Canvas.TextOut(Rect.Left + RowhorzOffset, Rect.Top +
47            RowVertOffset, vRowText);
48        if (dwgTable.RowCount - 1 = ARow) then
49          dwgTable.Canvas.TextOut(Rect.Left + ColhorzOffset, Rect.Top +
50            ColVertOffset, vColText);
51      end;
52    end
53    else
54    begin
55      dwgTable.Canvas.Brush.Color := clWindow;
56      dwgTable.Canvas.FillRect(Rect);
57    end;
58  end;
59  
60  procedure TForm1.dwgTableClick(Sender: TObject);
61  begin
62    ShowMessage('Col:' + Inttostr(dwgTable.ColCount - 1) + '
63      Row: 'dwgTable.RowCount-1));
64  end;



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC