在vb中打印带有图像的可滚动面板

时间:2015-06-04 11:09:49

标签: vb.net printing panel scrollable

大家好日子。我在可滚动面板中打印图像时遇到问题。任何人都可以帮我这个吗?

我想首先调整图像大小(因此它可以适合8.5 x 11“纸张),然后在打印预览中显示然后打印它

在我的情况下,我有一个带有面板(dock = fill)的表单(form1),我想在其中打印图像(2个图像)。但是,图像打印的触发器是下一种形式

在btnnext(form1)中      Form2.Show()      Me.Hide()

,打印代码为form2。我是vb的新手,我对打印可滚动面板一无所知。我在其他论坛尝试了不同的代码,但它没有打印整个图像,只打印了表单的截图。任何回复都将不胜感激。非常感谢你

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/accueil">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/font"
        android:src="@drawable/fond_menu"
        android:scaleType="centerCrop"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="20dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/topLogo"
                android:layout_marginTop="5dp"
                android:src="@drawable/logo_bleu_petit"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/topText"
                android:lineSpacingMultiplier="1.3"
                android:textSize="16sp"
                android:layout_below="@+id/topLogo"
                android:layout_centerHorizontal="true"
                android:width="260dp"
                android:layout_marginTop="15dp"
                android:gravity="center"
                android:textIsSelectable="false"
                android:layout_marginBottom="10dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/firstBlock"
                android:src="@drawable/encart_offres"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/topText"
                android:layout_alignParentRight="true"
                android:layout_marginRight="150dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/secondBlock"
                android:src="@drawable/encart_contact"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_below="@+id/topText"
                android:layout_alignParentBottom="false"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="false"
                android:layout_marginLeft="150dp" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/thirdBlock"
                android:src="@drawable/encart_actualites"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/firstBlock"
                android:layout_marginTop="40dp"
                android:layout_marginLeft="150dp"
                android:layout_alignParentRight="true" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/fourthBlock"
                android:src="@drawable/encart_mentions"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_below="@+id/secondBlock"
                android:layout_marginTop="40dp"
                android:layout_marginRight="150dp"
                android:layout_alignParentLeft="true" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="80dp"
                android:id="@+id/formulaire"
                android:layout_marginTop="15dp"
                android:layout_below="@+id/fourthBlock"
                android:background="@drawable/bouton_formulaire"
                android:layout_centerHorizontal="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/bottomText"
                android:lineSpacingMultiplier="1.2"
                android:gravity="center"
                android:textColor="#626262"
                android:textSize="14sp"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:width="270dp"
                android:layout_below="@+id/formulaire" />

        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

- ^它只打印您在屏幕上可以看到的内容。不是整个小组..

1 个答案:

答案 0 :(得分:-1)

基本上,保持一切相同,但不是在整个页面上打印整个第一张图像,而是将第二张图像打印成相对于MarginBounds的位置和大小的比率

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Using bmp As New Bitmap(Form1.pb1.Width, Form1.pb1.Height)
        Form1.pb1.DrawToBitmap(bmp, New Rectangle(0, 0, Form1.pb1.Width, Form1.pb1.Height))
        'Print pb1 to fill the whole page
        e.Graphics.DrawImage(bmp, e.MarginBounds)
    End Using
    Using bmp2 As New Bitmap(Form1.pb2.Width, Form1.pb2.Height)
        Form1.pb2.DrawToBitmap(bmp2, New Rectangle(0, 0, Form1.pb2.Width, Form1.pb2.Height))

        Dim x as Double = Form1.pb2.Location.X - Form1.pb1.Location.X
        x = x * e.MarginBounds.Width / Form1.pb1.Width
        x = x + e.MarginBounds.X

        Dim y as Double = Form1.pb2.Location.Y - Form1.pb1.Location.Y
        y = y * e.MarginBounds.Height / Form1.pb1.Height
        y = y + e.MarginBounds.Y

        Dim width as Double = Form1.pb2.width
        width = width * e.MarginBounds.Width / Form1.pb1.Width

        Dim height as Double = Form1.pb2.Height
        height = height * e.MarginBounds.Height / Form1.pb1.Height

        e.Graphics.DrawImage(bmp2, New Rectangle(x, y, width, height))
    End Using
End Sub