Error 1 Property 'Height' is 'ReadOnly'

HORNSWOGGLE

C++ Beginner
Hi,

Ich hab nen Problem,

Code:
pictureBox1.BackgroundImage.Height = 20

bei dem Code bringt er den Fehler immer wieso, was ist falsch?:confused:

Error 1 Property 'Height' is 'ReadOnly'

Kann mir jemand helfen?
 
Hi,

bei dem Property Height ist nur der Getter implementiert, deswegen kannst du nur lesend darauf zugreifen. Was genau willst du denn machen? Wenn es um einfaches Layout geht, dann schau dir mal das BackgroundImageLayout Property von PictureBox an. Ansonsten kannst du das Bild neu zeichnen und dann dem PictureBox erneut zuweisen.

Gruß Konstantin
 
Hab versucht aber nach BackgroundImageLayout kommt kein Size und das benötige ich doch oder?:confused:

Ich will die größe des BackgroundImages der PictureBox einstellen können, hab alles schon versucht?:confused:

Habs auch schon so probiert:

Code:
 pictureBox1.Size = New Size(20, 20)

geht aber auch nicht, hier sollte sich die PictureBox größe einstellen lassen?:confused:

Die Größe des BackgroundImage der PictureBox soll man einstellen können!
 
probier das hier mal aus:
C#:
pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
pictureBox1.Size = new Size(400, 600);
alternative Lösung wäre, du zeichnest es neu:
C#:
pictureBox1.BackgroundImageLayout = ImageLayout.Tile;
Image image = pictureBox1.BackgroundImage;
Bitmap bitmap = new Bitmap(200,200);
int newWidth = 20;
int newHeight = 20;

using (Graphics graphics = Graphics.FromImage(bitmap))
{
    graphics.DrawImage(image, 0, 0, newWidth, newHeight);
}

pictureBox1.BackgroundImage = bitmap;

Gruß Konstantin
 
Code:
pictureBox1.BackgroundImageLayout = ImageLay.Zoom
pictureBox1.Size = New Size(400, 600) 
 
pictureBox1.BackgroundImageLayout = ImageLay.Tile
Dim image As Image =  pictureBox1.BackgroundImage 
Dim bitmap As Bitmap =  New Bitmap(200,200) 
Dim NewWidth As Integer =  20 
Dim NewHeight As Integer =  20 
Imports (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImage(image, 0, 0, NewWidth, NewHeight)
}
 
pictureBox1.BackgroundImage = bitmap

hier ist ein online Converter: CSharp-To-Vb

Gruß Konstantin
 
Hab mal Konvertiert aber der Code stimmt immernoch nicht ganz,hier,

Code:
pictureBox1.BackgroundImageLayout = ImageLay.Zoom
pictureBox1.Size = Function Size(ByVal400, ByVal600) As New
graphics.DrawImage(image, 0, 0, NewWidth, NewHeight)
End Function
 
pictureBox1.BackgroundImage = bitmap

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net) 
'----------------------------------------------------------------

Es fehlen die Deklarationen die hab ich aber gemacht und trotzdem war das erste ByVal falsch?:confused:

Hier mein Programm Code:

Code:
Public Class Form1

    Private pictureBox1 As New PictureBox()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Dock the PictureBox to the form and set its background to white.
        pictureBox1.Dock = DockStyle.Fill
        pictureBox1.BackColor = Color.Transparent
        pictureBox1.BackgroundImage = My.Resources.Textleiste
        'Hier soll die größe des BackgroundImages der PictureBox ermittelt werden.


        ' Connect the Paint event of the PictureBox to the event handling method.
        AddHandler pictureBox1.Paint, AddressOf Me.PictureBox1_Paint

        ' Add the PictureBox control to the Form.
        Me.Controls.Add(pictureBox1)
    End Sub


    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics

        g.DrawString("deintext", New Font("Tahoma", 12, FontStyle.Bold), Brushes.White, New PointF(1.0F, 0.5F))

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Application.Exit()

    End Sub
End Class

Wieso geht das nicht?:confused:
 
Bevor man etwas entwickelt, sollte man sich genau überlegen was man eigentlich haben will und das auch so bei Fragen im Forum kommunizieren.
Also, was willst du? Die Größe von dem BackgroundImage ermitteln oder die Größe von dem BackgroundImage setzen?
2 Lösungen für das Ändern der Größe hast du von mir (u.a. in VB-Syntax) schon bekommen.

Gruß Konstantin
 
Also mal Klartext:

Ich will die größe des BackgroundImages der PictureBox ändern können,es soll aber ander selben Stelle (Location) bleiben
:(

es handelt sich um eine Titelleiste (PictureBox1) meines Fensters, das Bild ist zu niedrig bzw. zu dünn, es soll etwas höher gezeichnet werden, soll aber die Position nicht ändern, sprich zoom,Tile oder Stretch, wenn es auf None eingestellt ist, ist das Bild oben am Fenster, die Titelleiste, und so soll es bleiben, nur das Bild höher zeichnen!:mad:
 
Die Größe änderst du ja z.B. durchs neu Zeichnen des Bildes. Dabei sagst du welche Position(x,y) und welche Größe(width,height) das Bild(BackgroundImage) hat.

Code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Namespace WindowsApplication1
	Public Partial Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
			pictureBox1.BackgroundImageLayout = ImageLayout.None
		End Sub
		Private image As Image = Image.FromFile("c:\test.png")

		Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
			Dim bitmap As New Bitmap(pictureBox1.Width, pictureBox1.Height)
			Using graphics As Graphics = Graphics.FromImage(bitmap)
				graphics.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height)
			End Using

			pictureBox1.BackgroundImage = bitmap
		End Sub

	End Class
End Namespace

Gruß Konstantin
 

Neue Beiträge

Zurück