Results 1 to 7 of 7

Thread: HELP ME PLZ<<URGENT

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    15

    HELP ME PLZ<<URGENT

    I HAV TWO QUESTIONS ( I AM USING VB.NET2003)

    1- HOW CAN I MAKE THE BACKGROUNDIMAGE OF THE FORM NOT TO BE TILE ,, I WANT IT TO BE STRECH (IN THE CENTER)

    2- IF I HAVE A BUTTON AND A PICTUREBOX IN A FORM ,, HOW CAN I PRINT THE PICTURE ONLY (NOT THE FULL FORM) WHEN CLICKING ON THE BUTTON.

    THX

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: HELP ME PLZ<<URGENT

    Answers for:
    1. Set your form's BackgroundImageLayout property to "Stretch".
    2. You need to use a PrintDocument component, and do the printing in the PrintPage event.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    15

    Re: HELP ME PLZ<<URGENT

    WHERE CAN I GET THE BackgroundImageLayout property , I'M NOT GETTING IT IN VB.NET2003

    (You need to use a PrintDocument component, and do the printing in the PrintPage event)
    COULD YOU EXPLAIN MORE?? CUZ I DIDN'T USE THIS COMPONENT EVER

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: HELP ME PLZ<<URGENT

    Didn't pay attention to your vb.net version on the first post.... For VB.Net 2003, you pretty much have to resize the background image yourself. And here is one way of doing it (Assuming that you already set your form's backgroundimage property to some image, now you just need to handle the resize in form load and form resize events)
    VB Code:
    1. Private bgImage As Image = Nothing
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, _
    4.                            ByVal e As System.EventArgs) _
    5.                            Handles MyBase.Load
    6.         bgImage = Me.BackgroundImage
    7.         StretchBackground()
    8.     End Sub
    9.  
    10.     Private Sub Form1_Resize(ByVal sender As Object, _
    11.                              ByVal e As System.EventArgs) _
    12.                              Handles MyBase.Resize
    13.         If Not Me.WindowState = FormWindowState.Minimized Then
    14.             StretchBackground()
    15.         End If
    16.     End Sub
    17.  
    18.     Private Sub StretchBackground()
    19.         If Not bgImage Is Nothing Then
    20.             Me.BackgroundImage = ResizeImage(bgImage, _
    21.                                              Me.ClientSize.Width, _
    22.                                              Me.ClientSize.Height)
    23.         End If
    24.     End Sub
    25.  
    26.     Private Function ResizeImage(ByVal img As Image, _
    27.                                  ByVal width As Integer, _
    28.                                  ByVal height As Integer) As Bitmap
    29.         Dim bm As New Bitmap(width, height)
    30.         Dim g As Graphics = Graphics.FromImage(bm)
    31.         g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    32.         g.DrawImage(img, 0, 0, width, height)
    33.         Return bm
    34.     End Function
    For using a PrintDocument, you can search the forum... There are already many examples on it, so I don't want to reinvent the wheel

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    15

    Re: HELP ME PLZ<<URGENT

    Thx Alot, But The Img Is Is Still Tile At The Design Time , It Is Strech Only When Running The Program, ( And Actually I Need To Assign Some Transparent Lables On Specific Locations On The Image)

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: HELP ME PLZ<<URGENT

    To stretch it at design time, you will simply need to size the image correctly for the form, and paste it on. I don't think there is a way to automate this, as I can't see any reason why there should be.
    My usual boring signature: Nothing

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: HELP ME PLZ<<URGENT

    why not something like this

    VB Code:
    1. Private _BGImage As Image = Image.FromFile("c:\bgimage.jpg")
    2.  
    3.     Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    4.         e.Graphics.DrawImage(_BGImage, e.ClipRectangle)
    5.     End Sub
    6.  
    7.  
    8.     Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
    9.         Me.Invalidate()
    10.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width