Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TPanel ? 1

Status
Not open for further replies.

cppdev

Programmer
May 12, 2003
23
US
I need a text area on a form, probably using a TPanel, of a specified size, 20 columns wide by 30 lines tall. Can this be specified in terms of columns and lines of characters?

the only specification for height and width i see is in pixels.


I am using Borland C++ Builder 6.0 with the latest patch installed.

Thanks in advance for assistance ,
cpp
 
I think you would want to use a TMemo instead, or TRichEdit. Since neither of these (if memory serves me right) has a TCanvas to draw to, you need to make a temporary one to test the width and height of the text.
Call a similar routine at creation. Be sure to use a fixed size font.

// Create a temporary Canvas
TCanvas *pCanvas = new TCanvas;

// Assign your row and column count
int iColumnCount = 30;
int iRowCount = 30;

// X and Y are for adding a bit more space to the Memo.
// Adjust them as needed after viewing the results.
int X = 10;
int Y = 10;

// Assign the font from the Memo to the Canvas
pCanvas->Font->Assign(Memo1->Font);

// Get width and height of each letter
int iTextWidth = pCanvas->TextWidth("A");
int iTextHeight = pCanvas->TextHeight("A");

Memo1->Width = iTextWidth*iColumnCount + X;
Memo1->Height = iTextHeight*iRowCount + Y;

I think this will work. You might have to move the X or Y into the multiplicand. ex: (iTextWidth + X)*iColumnCount;

You could run this every time the user types something if you want to use non-fixed sized fonts (but I'm not sure that you can even use non-fixed in a Memo field).

Hope it helps,
Chris
 
Thanks Chris, I believe that is exactly what i need.

Cpp
 
can you actually set fields within TRichEdit or TMemo?
Or would
you be repainting the whole section for any changes?
 
Set fields? You can set line by line. Use Memo1->Lines->Strings[x] to change them. Is that what you mean?

Chris
 
I need to be able to select a group of characters and define these selected characters as a certain type, e.g. decimal, alpha, integer, currency, date, etc......, It is possible that one line could contain more than one type of data. This is what i mean by defining fields.

Thanks in advance.
 
Howdy,

If you want to execute a search on the text, and test it so that it fits into one or other categories, the TRichEdit component has built-in Find() functions.

That may be of some use, but what exactly are you trying to accomplish? Could you be more specific?

Hope I could help,
onrdbandit
 
I'm thinking there is probably another component to make life much easier on you. However, you can still do what you want to do like such:

int x;
int y;

for (y=0; y < RowCount; y++)
{
AnsiString TempString;

char TempChars[11] // assuming 10 chars per field
for (x=0; x < ColumnCount; x++)
{
TempChars[x] = Memo1->Lines->Strings[y].SubString(x, 1);
}
TempChars[10] = NULL;
TempString = TempChars;
}

or

for (y=0; y < RowCount; y++)
{
AnsiString
Field1 = Memo1->Lines->Strings[y].SubString(0, 5),
Field2 = Memo1->Lines->Strings[y].SubString(6, 5),
Field3 = Memo1->Lines->Strings[y].SubString(11, 5);

// Use Field1, 2, 3.
}
 
Sorry, the snipet that says:
for (x=0; x < ColumnCount; x++)
{
TempChars[x] = Memo1->Lines->Strings[y].SubString(x, 1);
}

should be:
for (x=0; x < 10; x++)
{
TempChars[x] = Memo1->Lines->Strings[y].SubString(x, 1);
}
 
Also, the snipet:
AnsiString
Field1 = Memo1->Lines->Strings[y].SubString(0, 5),
Field2 = Memo1->Lines->Strings[y].SubString(6, 5),
Field3 = Memo1->Lines->Strings[y].SubString(11, 5);

could possibly have to be:
AnsiString
Field1 = Memo1->Lines->Strings[y].SubString(0, 5),
Field2 = Memo1->Lines->Strings[y].SubString(5, 5),
Field3 = Memo1->Lines->Strings[y].SubString(10, 5);

assuming 5 is the field size.

Chris
 
I am sure you could also use your tpanel for a backdrop for a grid of tlabel. this might be time consuming to make the array necessary to contain the positions of the grid col and rows. I depends on what you are wanting the end product to look like. I have an app that uses a grid array that contains the coordinates that are then display on a button click. I divided an image into a grid 21x11, each square is linked to a table. time consuming but adequate for the job.

tomcruz.net
 
You could definitely use TLabel on a Panel to do what you're looking for. To access the array, you would want to create a list and store each label separately.

For instance, if the Panel looked like this:

Label1 Label2 Label3 Label4
Label5 Label6 Label7 Label8
etc...

Create a TList on form creation that adds the labels.

TList *FieldList = new TList();
FieldList->Add(Label1);
FieldList->Add(Label2);
FieldList->Add(Label3);
FieldList->Add(Label4);
FieldList->Add(Label5);
FieldList->Add(Label6);
FieldList->Add(Label7);
FieldList->Add(Label8);
etc...

Then when you pass in X for the column value to access, and you pass in Y for the row value to access, just create an Index value.

int ColumnCount = 4; // Four columns in example above

TLabel* __fastcall GetLabel(int X, int Y)
{
int Index = Y*ColumnCount + X;

TLabel *SelectedLabel = (TLabel*) FieldList->Items[Index];
return SelectedLabel;
}

GetLabel(0,0) returns Label1.
GetLabel(1,0) returns Label2.
GetLabel(0,1) returns Label5.

Chris
 
I think what i am looking for is :
1) a way to modify this part of the gui just using the mouse.

in other words, i will select a continous group of spaces with the mouse, specify the field type (int, decimal, date, etc.. ) and other relevant data in a seperarate part of the gui.

I might want to color code the differnt field types, or place some relevant text , such as in the area specified as DATE field i might put &quot;DATE&quot;, etc....

another thing i might do is to eventually write my own paint routine to only recolor a specific area that has been changed.


Thanks for the help.
cpp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top