English 中文(简体)
如何在c#中拯救小组的内容?
原标题:how to save the content of a panel in c#?
  • 时间:2011-05-04 13:23:05
  •  标签:
  • c#
  • asp.net

I m working on a project in c # and I have a problem with saving my panel. I have a listbox were I chose the form that I want to load into my panel. But when I want to save my panel it s impossible to read the content of it. After saving my panel i want to convert it to a pdf document but when i can t save it it s impossible to do that. Can somebody help me please ?

    protected void btnPDF_Click(object sender, EventArgs e)
    {
        int teller = 0;

        foreach (Control Ctrl in pnlMain.Controls)
        {
            if (Ctrl is Label)
            {
                teller++;
            }

        }

        int teller2 = 0;
        Label[] arr_label = new Label[teller];

        foreach (Control Ctrl in pnlMain.Controls)
        {
            if (Ctrl is Label)
            {
                Label lbl_Ctrl = Ctrl as Label;
                arr_label[teller2] = lbl_Ctrl;
                teller2++;
            }
        }

        int teller3 = 0;
        int lengte = arr_label.Length;
        String hulp1;


        //aanmaken van uw document
        var doc1 = new Document(PageSize.A4, 50, 50, 25, 25);

        //aanmaken van  de outputstream
        var output = new MemoryStream(); //geen extra argumenten nodig

        //aanmaken van een "pdfwriter document"
        var writer = PdfWriter.GetInstance(doc1, output);

        //voor je in je document iets kan "schrijven" moet je het eerst openen:
        doc1.Open();

        while (teller3 < lengte)
        {
            Label hulp;

            hulp = arr_label[teller3];
            hulp1 = hulp.Text;
            teller3++;

            //bepaal de inhoud van je pdf document (locatie)
            string inhoud = File.ReadAllText(Server.MapPath("pdf.aspx"));
            var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(hulp1), null);

            //alle elementen van uw pagina in de pdf steken (foreach.... zeer handige functie)
            foreach (var htmlElement in parsedHtmlElements)
                doc1.Add(htmlElement as IElement);

        }
        //nu de pdf gemaakt is gaan we de boel afsluiten:
        doc1.Close();

        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename= Evaluatierapport.pdf"));
        Response.BinaryWrite(output.ToArray());       
    }





      private void btnSave_Click(object sender, EventArgs e) 
      {
          SaveFileDialog saveFileDialog = new SaveFileDialog();

          saveFileDialog.DefaultExt = "bmp";
          saveFileDialog.Filter = "Bitmap files|*.bmp";
          if (saveFileDialog.ShowDialog() == DialogResult.OK)
          {
              int width = pnlMain.Width;
              int height = panel.Height;

              Bitmap bitMap = new Bitmap(width, height);
              System.Drawing.Rectangle rec = new Rectangle(0, 0, width, height);

              panel.DrawToBitmap(bitMap, rec);

              bitMap.Save(saveFileDialog.FileName);
          }
      }
}
问题回答

顺便说一句,我相信,你会重新积极控制:

I have a listbox were I chose the form that I want to load into my panel.

强有力的附加控制不会通过后退而持续下去。 你们需要用同样的斜线......或用自己的眼光ft。

[编辑]

探讨这些问题:

[/编辑]





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签