Location, location, location...
Location, location, location...
Location, location, location...
Location, location, location...
Location, location, location...
Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location...
Location, location, location... Location, location, location...
Location, location, location...
Go Back  Xtreme Visual Basic Talk > > > Location, location, location...


Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2014, 08:03 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Question Location, location, location...


Ok, I am creating a decryption puzzle. It dynamically creates object loaded panels within a fixed panel.
The problem is when a dynamically created panel (WordPanel) would extend beyond the right edge of the fixed panel (Panel1), it needs to drop down and start a new line (row) at Panel1's left edge.
Code:
            Panel1.Controls.Add(WordPanel)
            WordPanel.Location = Pnt

            If WordPanel.Right > Panel1.Right Then
                'Start a new line
                Pnt.Y = Pnt.Y + 35
                Pnt.X = 0
                WordPanel.Location = Pnt
            End If
            Pnt.X = Pnt.X + 30
        Next
It does drop down by 35 pixels, but doesn't go back to the left edge of Panel1.
I have even tried using 'WordPanel.left = Panel1.left, but still no luck.
__________________
Amerigo
Reply With Quote
  #2  
Old 01-18-2014, 08:06 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

Tried that. Same results.
__________________
Amerigo
Reply With Quote
  #3  
Old 01-19-2014, 10:03 AM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

In that case I do not know based on the code you posted.

Personally I never use individual controls to generate game grids.
I always found it easier to create an engine that draws the display based
on the contents of a 2D array. Adjust the contents and let the engine
redraw everything.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #4  
Old 01-20-2014, 09:31 AM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

What it's supposed to do, is take a random quote and make a panel (WordPanel) for each word in the quote, then add the panel to the pre-existing Panel1. It will also mask each letter with a photo assigned to that letter (not yet coded).
The problem is getting it to 'wrap' like wordwrap in a textbox.

Code:
    Private Sub NewPuzzle()

        GetQuote()

        'Dim Words() As String = Split(" ", )
        Dim word As String
        For I As Integer = 0 To Quote.Split(" ").Length - 1 Step 1
            word = Quote.Split(" ")(I)
            Dim WordPanel As New Panel
            WordPanel.Height = 30
            WordPanel.Width = 30
            WordPanel.AutoSize = True
            'WordPanel.BackColor = Color.Blue
            For Each C As Char In word.ToUpper
                Dim pic As New Button
                pic.FlatAppearance.BorderColor = Color.Black
                pic.FlatAppearance.MouseDownBackColor = Color.Black
                pic.FlatAppearance.MouseOverBackColor = Color.Black
                pic.FlatStyle = FlatStyle.Flat

                pic.Tag = C
                pic.Text = C
                'If C <> " " Then
                '    pic.BackgroundImage = Image.FromFile(Application.StartupPath & "\Symbols\x32logo.jpg")
                'End If
                pic.Size = New Size(20, 30)
                pic.BackgroundImageLayout = PictureBoxSizeMode.StretchImage
                pic.Location = New Point(A, 0)
                WordPanel.Controls.Add(pic)
                A = A + 20
            Next

            WordPanel.Location = New Point(Pnt)
            If WordPanel.Right > Panel1.Right Then
                'Start a new line
                Pnt.Y = Pnt.Y + 35
                Pnt.X = 0
                WordPanel.Location = New Point(Pnt)
            End If
            'Stretcher.Text = WordPanel.Location.ToString
            Panel1.Controls.Add(WordPanel)
            Pnt.X = Pnt.X + 30
        Next

    End Sub
__________________
Amerigo
Reply With Quote
  #5  
Old 01-20-2014, 09:58 AM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

I will not get into all the errors I see elsewhere in your code,
but regarding your issue with wordpanel:

You are trying to set its position before you add it to the panel.
You have to set its position within the panel after it has been added to the panel.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #6  
Old 01-20-2014, 07:24 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

I understand my code may be cludgy as I am a self taught amateur. How would you do this differently keeping in mind that each letter of the quote must be able to switch back and forth between letters and images? Incidentally, I'm not getting any errors when debugging, except that WordPanels are not behaving properly.
__________________
Amerigo
Reply With Quote
  #7  
Old 01-21-2014, 11:00 AM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Where I am having problems is in getting a clear picture of what you want to achieve.

Is this image correct or do you also want each letter to be in its own equal sized box for each word?
Attached Images
File Type: png word parse.png (9.0 KB, 8 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #8  
Old 01-21-2014, 01:52 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

Sort of... Each letter in a word populates in a new button. Each set of buttons representing a complete word is added to a new panel (Word Panel) that is equal in height to the buttons and as long as the set of buttons. In the following, | | represents Panel1, [ ] = a WordPanel, and () = a lettered button.

Quote:
|[(I)] [(L)(o)(v)(e)] [(V)(i)(s)(u)(a)(l)] |
|[(b)(a)(s)(i)(c)]___________________|
Attached is a screenshot of what I'm getting...
Attached Images
File Type: jpg scrnsht.jpg (11.4 KB, 11 views)
__________________
Amerigo
Reply With Quote
  #9  
Old 01-21-2014, 02:55 PM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Did you know that without using a ton of panels you can parse words and letters directly out of the RichTextBox control. The following snippet will do so and colorize the selected word and letter on a double click.

Code:
Public Class Form1 Private Sub RichTextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown ' Prevent editing in the richtextbox e.SuppressKeyPress = True e.Handled = True End Sub Private Sub RichTextBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown With RichTextBox1 ' Save Current selection settings Dim CurrStart As Integer = .SelectionStart Dim CurrLength As Integer = .SelectionLength ' Clear all colors .SelectionStart = 0 .SelectionLength = .TextLength .SelectionColor = Color.Black ' Colorize the current word .SelectionStart = CurrStart .SelectionLength = CurrLength .SelectionColor = Color.Blue ' Display the selected word in a label Label1.Text = .SelectedText.Trim ' Colorize the current letter .SelectionStart = .GetCharIndexFromPosition(e.Location) .SelectionLength = 1 .SelectionColor = Color.Red ' Display selected letter in a label Label2.Text = .GetCharFromPosition(e.Location) ' Show Changes .SelectionStart = 0 .SelectionLength = 0 .Focus() End With End Sub End Class
Attached Images
File Type: png Word_Letter_Select.png (8.3 KB, 8 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #10  
Old 01-21-2014, 03:28 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

I will definitely use that in my text editor program. In this case, I am breaking down the Quote to separate buttons, so that they can be masked by images. The user will then have to figure out what the quote is by decoding it.
For example, in this word: %$#^&'@ with the apostrophe unchanged; you could guess that the @ is an S or T. A single letter word you would know to be either an A or I, and so forth.
When the user guesses that @ = S, then every image(@), will be removed and the text changed to what the user thinks it is. What it really is, will be stored in that button.tag.
__________________
Amerigo
Reply With Quote
  #11  
Old 01-21-2014, 04:14 PM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Okay,

I guess I would start with knowns and work from there.

1) I would make the width of the program divisible by the width of the characters.
2) I would know how many characters would fit across. (Columns)
3) I would then fit my words across each line bumping to the next line when a word
could not complete within the columns.
4) I would probably do this in the msflexgrid control or the datagridview control as
it is already a 2D matrix. (I see no benefit from grouping each word or letter into a separate panel.)

A 2D Grid can be transposed into a 1D array and back easily if needed.

Basically I would map the real characters to a 2D array.
Swap out the real characters with images.

When the user guesses a letter you find the image cell and directly lookup the real letter.
in the 2D array. If correct you swap out the real letter and image in the grid.

As I said before this could also be done by simply drawing what you want on one panel or picturebox.
Trying to use individual controls is a waste of resources and overly complex.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #12  
Old 01-21-2014, 05:38 PM
passel's Avatar
passelLocation, location, location... passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Since the backcolor of your word panel is the same as panel1 it is hard to see if the word panel is the correct size, and is missleading you. Set the background color of the word panels to a different color from panel1, so you can verify where they are being placed, otherwise you can only tell where the character panels are, not the word panels.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #13  
Old 01-21-2014, 06:08 PM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Sample of drawing grids from an array with wrapping letters.
The array contains two character strings in each element.
A leading tilde (~) followed by the phrase letter.

When in game mode those elements with a tilde are shown as
a 'Windings' font icon. When the correct letter is pressed from the keyboard
the tilde is removed and the phrase letter is displayed.

Current cell is highlighted yellow
Punctuation cell text is red
Icons are blue
Correct Text is black.

No controls needed.

Code:
Public Class Form1 ' Form: FontSize = 16 Bold '=== Form Controls === ' Label: lblCoordinate FontSize = 16 ' Textbox: txtPhrase FontSize = 16 ' Button: cmdFill FontSize = 10 ' Button: cmdTestAnswer FontSize = 10 ' Button: cmdTestGame FontSize = 10 ' Picturebox: P1 '===================== Const Square As Integer = 32 Const MaxCols As Integer = 20 Const MaxRows As Integer = 8 Const CharAdjust As Integer = 10 'Adjust char ascii value for simple scramble Dim Board(MaxCols, MaxRows) As String Dim DrawAnswerBoard As Boolean = False Dim DrawMaskBoard As Boolean = False Dim PX As Integer = 0 Dim PY As Integer = 0 Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp 'We need form.keypreview turned on as the picturebox has no keyboard events. Dim sLetter As String = Board(PX, PY) If sLetter <> "" Then If sLetter.Length > 1 Then sLetter = sLetter.Last If Chr(e.KeyData) = sLetter Then ReplaceAll(sLetter) P1.Invalidate() End If End If End If End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim HtMargin As Double = (P1.Height - P1.ClientRectangle.Height) / 2 Dim WtMargin As Double = (P1.Width - P1.ClientRectangle.Width) / 2 P1.Height = CInt(Square * (MaxRows) + HtMargin) P1.Width = CInt(Square * (MaxCols) + WtMargin) End Sub Private Sub P1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles P1.MouseUp PX = e.X \ Square PY = e.Y \ Square lblCoordinate.Text = PX.ToString & ", " & PY.ToString P1.Invalidate() End Sub Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles P1.Paint With e.Graphics For i = 0 To MaxRows - 1 If i > 0 Then .DrawLine(Pens.Black, 0, Square * i, P1.ClientRectangle.Width, Square * i) End If Next For i As Integer = 0 To MaxCols - 1 If i > 0 Then .DrawLine(Pens.Black, Square * i, 0, Square * i, P1.ClientRectangle.Height) End If Next If DrawAnswerBoard = True Then For Row As Integer = 0 To MaxRows - 1 For Col As Integer = 0 To MaxCols - 1 Dim sLetter As String = Board(Col, Row) If sLetter <> "" Then Dim Rect As New Rectangle(Square * Col, Square * Row, Square, Square) Dim SF As New StringFormat SF.Alignment = StringAlignment.Center SF.LineAlignment = StringAlignment.Center SF.Trimming = StringTrimming.None .DrawString(sLetter.Last, Me.Font, Brushes.Blue, Rect, SF) End If Next Next End If If DrawMaskBoard = True Then For Row As Integer = 0 To MaxRows - 1 For Col As Integer = 0 To MaxCols - 1 Dim sLetter As String = Board(Col, Row) If sLetter <> "" Then If Row = PY And Col = PX Then Dim HighLiteRect As Rectangle = New Rectangle(Col * Square + 2, Row * Square + 2, Square - 4, Square - 4) .FillRectangle(Brushes.Yellow, HighLiteRect) End If Dim Rect As New Rectangle(Square * Col, Square * Row, Square, Square) Dim SF As New StringFormat SF.Alignment = StringAlignment.Center SF.LineAlignment = StringAlignment.Center SF.Trimming = StringTrimming.None If sLetter.Length = 1 Then .DrawString(sLetter, Me.Font, Brushes.Black, Rect, SF) ElseIf (",.!? ").Contains(sLetter.Last) Then .DrawString(sLetter.Last, Me.Font, Brushes.Red, Rect, SF) Else Dim IconFont As Font = New Font("Webdings", 16) Dim CharValue As Integer = Asc(sLetter.Last) + CharAdjust sLetter = Chr(CharValue) .DrawString(sLetter, IconFont, Brushes.Blue, Rect, SF) End If End If Next Next End If End With End Sub Private Sub cmdFill_Click(sender As System.Object, e As System.EventArgs) Handles cmdFill.Click Dim Row As Integer = 0 Dim Col As Integer = 0 Dim sWords() = txtPhrase.Text.Split(" "c) For Each sWord As String In sWords sWord &= " " If sWord.Length > MaxCols - Col Then Col = 0 Row += 1 End If For Each sLetter As Char In sWord.ToCharArray Board(Col, Row) = "~" & sLetter Col += 1 Next Next End Sub Private Sub cmdTestAnswer_Click(sender As System.Object, e As System.EventArgs) Handles cmdTestAnswer.Click DrawAnswerBoard = True DrawMaskBoard = False P1.Invalidate() End Sub Private Sub cmdTestMask_Click(sender As System.Object, e As System.EventArgs) Handles cmdTestGame.Click DrawMaskBoard = True DrawAnswerBoard = False P1.Invalidate() End Sub Private Sub ReplaceAll(sLetter As String) For row As Integer = 0 To MaxRows For col As Integer = 0 To MaxCols Dim sCurrLetter As String = Board(col, row) If sCurrLetter <> "" Then If sLetter = sCurrLetter.Last Then Board(col, row) = sLetter End If End If Next Next End Sub End Class
Attached Images
File Type: png WordPuzzleII.png (21.0 KB, 9 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 01-22-2014 at 11:47 AM.
Reply With Quote
  #14  
Old 01-21-2014, 06:21 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

@ Graff: Awesome. Thanks.
@ Passel: You're right. If forgot to reset 'A' to 0.
__________________
Amerigo
Reply With Quote
  #15  
Old 01-22-2014, 11:52 AM
Gruff's Avatar
GruffLocation, location, location... Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Updated my last post (#13) to be a working test bed for your actual game.
It highlights the selected cell in yellow. Clicking the correct key on the keyboard
for the selected cell updates the cell from an icon to the correct letter.

I used Wingdings font icons for the images.

Seems to work fine.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply

Tags
coordinates, location


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Location, location, location...
Location, location, location...
Location, location, location... Location, location, location...
Location, location, location...
Location, location, location...
Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location... Location, location, location...
Location, location, location...
Location, location, location...
 
Location, location, location...
Location, location, location...
 
-->