Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi Guys,

Could anyone help me how to convert in easy manner below text file as drawing using squares with X and * inside + with color.It mus appear graphical with color for easy view.


*XX*XXX*
**XXXX*XXXXX**
*XXXXXX*XXXXXXX*

Sorry i can t paste the sample drawing.
Thanks.
br,
george

Thanks for your intention to help me. I am new to programming specially to drawing using gdi. The purpose of the program is i want to transpose the text file into colored one like below ouput. But inside the colored box is the X or *.
Posted
Updated 11-Feb-10 17:48pm
v3

Drawing where ? Using which libraries ?
Where are you stuck precisely ? Because for now, you didn't provide any information on what your exact problem is.
 
Share this answer
 
I deleted your 'answer' that was really another question and pasted it into your original post via the edit button. Now I can see all you wrote as I reply

If you're new to programming, then this is probably a difficult task to attempt, why are you doing it ?

Having said that, it's not that hard to step over a string, and draw boxes of different colors that are all the same size. I'd imagine you'd have a nested for loop, use those variables to index into your text square, then you'd use those same values to calculate the square and set the color based on the text content.
 
Share this answer
 
gfaz wrote:
Thanks for your intention to help me. I am new to programming specially to drawing using gdi. The purpose of the program is i want to transpose the text file into colored one like below ouput. But inside the colored box is the X or *.


Well, you simply repeated what you already said. But you still didn't answer the questions: which "graphical library" are you using for the rendering ? Pure MFC, OpenGL, DirectX, ... ?
Also you didn't reply to the other question: where are you stuck exactly ? We can't provide you with the full code, so the more vague your question is, the more vague the answer will be. If you want a clear answer, ask a clear question (and keep in mind that we won't give you "the full codez").
 
Share this answer
 
I suppose you want to represent on the screen (the way you told) the text file content.
To render graphics on the screen, you need to handle the Windows WM_PAINT message (see "Painting and Drawing") and use some GDI functions, like Rectangle, DrawText, etc.
:)
 
Share this answer
 
Thank Guys for giving hints. I am sorry I forgot to add the flow or sample code. I did some perspiration and research using mdsn i think i got what i want:

VB
Imports system.io
Public Class Form1
    Dim fileContents As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles MyBase.Load
        'Read the file and write to richtextbox
        fileContents = My.Computer.FileSystem.ReadAllText("C:\File1.txt")
        RichTextBox1.Text = fileContents

    End Sub

    Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim txtBrush As SolidBrush = New SolidBrush(Color.Black)
        Dim timeNewRoman As Font = New Font("Times New Roman", 12, FontStyle.Regular)
        Dim aLine As String
        Dim xposition, yposition As Short
        yposition = 1
        'stringreader
        Dim strReader As New StringReader(RichTextBox1.Text)
        Do While strReader.Peek <> -1
            aLine = strReader.ReadLine()
            'reset xposition
            xposition = 1
            For Each ss As String In aLine
                'increment xposition
                xposition += 1
                If Char.IsLetter(ss) Then
                    Dim penCurrent As New Pen(Color.Red)
                    Dim rect As New Rectangle(20 * xposition, 20 * yposition, 20, 20)
                    e.Graphics.DrawRectangle(penCurrent, rect)
                    Dim Brush As SolidBrush = New SolidBrush(Color.Aqua)
                    g.FillRectangle(Brush, 20 * xposition, 20 * yposition, 19, 19)
                    g.DrawString(ss, timeNewRoman, txtBrush, 20 * xposition, 20 * yposition)
                ElseIf ss = "*" Then
                    Dim penCurrent As New Pen(Color.Blue)
                    Dim rect As New Rectangle(20 * xposition, 20 * yposition, 20, 20)
                    e.Graphics.DrawRectangle(penCurrent, rect)
                    Dim Brush As SolidBrush = New SolidBrush(Color.Yellow)
                    g.FillRectangle(Brush, 20 * xposition, 20 * yposition, 19, 19)
                End If

            Next

            yposition += 1

        Loop


    End Sub

End Class


>>>>Thanks guys.. Hope to answer me in next questions..I am new to using GDI. I am more on database and asp.net
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900