如何将结构信息写入PictureBox? [英] How I can write structure information into PictureBox ?

查看:49
本文介绍了如何将结构信息写入PictureBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我是C#的新手,我正为这项任务而苦苦挣扎.如何将该结构信息写入PictureBox?

Hi everybody. I''m new with c# and i''m struggling with this task. How I can write this struct information into PictureBox?

public struct Kauppa
       {
           private string mShop;
           private string mAddress;
           private string mRegion;
           private string mPostal;
           private string mLine1;
           private string mLine2;
           private string mLine3;
         

           public string Shop
           {
               get
               {
                   return mShop;
               }
               set
               {
                   mShop = value;
               }
           }
           public string Address
           {
               get
               {
                   return mAddress;
               }
               set
               {
                   mAddress = value;
               }
           }...





public void Information()
      {
          Kauppa K = new Kauppa();
          K.Shop = this.txtShop.Text;
          K.Address  = this.txtStreet.Text;
          K.Region = this.txtRegion.Text ;
          K.Postal = this.txtPostalcode.Text;
          K.Line1 = this.txtLine1.Text;
          K.Line2 = this.txtLine2.Text;
          K.Line3 = this.txtLine3.Text;
       
      }

推荐答案

为什么要这么做?
有可能,但我不确定为什么您会想要...

为此,请处理PictureBox Paint事件:
Why do you want to do that?
It is possible, but I''m not sure why you would want to...

To do it, handle the PictureBox Paint Event:
Kuppa myKuppa;
Font myFont = new Font("Arial", 10);
private void myPictureBox_Paint(object sender, PaintEventArgs e)
    {
    if (myKuppa != null)
        {
        Graphics g = e.Graphics;
        g.DrawString(myKuppa.Shop, myFont, Brushes.Black, 0, 0);
        ...
        }
    }

在您的Information方法(或任何位置)中,将一个实例分配给myKuppa并使PictureBox无效-最后一位使其重新绘制.

In your Information method (or wherever) assign an instance to myKuppa and invalidate the PictureBox - the last bit makes it repaint.

Kauppa K = new Kauppa();
K.Shop = this.txtShop.Text;
...
myKuppa = K;
myPictureBox.Invalidate();




我希望从这些信息中打印出收据,我认为Picturebox对此很有用.感谢您的回答.


不!图片框对此非常不利! :laugh:

主要问题是PictureBox的屏幕分辨率:一般为72 dpi.由于您的打印机将在> 300 dpi,输出看起来真的非常糟糕!

相反,请查看 PrintDocument类 [




I want print receipt from that information and I thought picturebox is good for that. Thanks for the answer.


No! A Picture box is very bad for that! :laugh:

The main problem is that a PictureBox is in Screen resolution: 72 dpi generaly. Since your printer will print at > 300 dpi, the output will look really, really bad!

Instead, look at the PrintDocument class[^] - it includes an example - which will work a whole lot better!


这篇关于如何将结构信息写入PictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆