Ticket Q94644
Visible to All Users

Create Custom Control in XtraReport, Using Bricks, Draw any Graphic (Line, Curves...) to selfmade Control

created 17 years ago

Hello,
we have created our own custom bricks. How we can use a class derived from XRControl that uses our own bricks…?
Please see the attachment.
I've read a lot of the examples, but the examples doesn't solve the problem.
Thank you for your help!
Greetings

Show previous comments (4)
DevExpress Support Team 17 years ago

    Hi Andy,
    The IGraphicks is an XtraPrintingSystem interface which provides methods similar to the System.Drawing.Graphics to draw the content in the XtraPrinting system.
    Could you clarify why you need to use the System.Drawing.Graphics class?
    Thanks,
    Andrew

      Hi Andrew,
      we have a graphical in-house component which displays something like shapes, contours, grids and so on. This component draws on an instance of the System.Drawing.Graphics object.
      We now want to print out the graphical contents of this component, so I created an own brick (let’s call it ExampleBrick) derived from Accessible and IBrick. The draw method I have to implement (IBrick.Draw) provides me with an instance of a System.Drawing.Graphics object which I need for my component to draw onto it. This works perfectly. For designing my report in XtraReport I also created my own Control derived from XRControl. As you know, I have to override the methods CreateBrick(…) and PutStateToBrick(…). The method CreateBrick(…) returns an instance of VisualBrick, but the problem is now that I cannot cast my ExampleBrick to VisualBrick.
      So I derived my ExampleBrick from VisualBrick. The casting now works fine, but not the drawing. VisualBrick doesn’t provide me with a method that has an instance of a System.Drawing.Graphics object as parameter. All the draw methods from VisualBrick like DrawClientContent(…), DrawObject(…), etc. only provide an instance of IGraphics, which I cannot use, because my component can only draw to a System.Drawing.Graphics object as I described above. How can I access a System.Drawing.Graphics object from VisualBrick?
      We plan to use XtraReports as well as XtraPrinting, so therefore I definitively need a class derived from XRControl which uses my own brick for designing the report. How can I realize that?

      I know there is control called WinControlContainer in XtraReports, but I cannot use it, because the printing quality doesn't meet my company’s requirements.
      I’m looking forward for your answer, and thanks for your help in advance,
      Andy

      DevExpress Support Team 17 years ago

        Hi Andy,
        Thank you for the feedback.
        The bricks, which are used in the XtraReport suite, should be inherited from the VisualBrick.
        I believe that you may use two different approaches to accomplish this task.

        1. You may create a Bitmap with the required resolution and use Graphics to draw the required content. Then draw this image inside the Report with the help of the Graphics.DrawImage method.
          For example:
                    Bitmap bmp = new Bitmap((int)rect.Width * 3, (int)rect.Height * 3, PixelFormat.Format24bppRgb);
                     Graphics wgr = Graphics.FromImage(bmp);
                     wgr.DrawEllipse(new Pen(this.Style.ForeColor), rect);
                     gr.DrawImage(bmp, rect);
        2. You may extract the Graphics from the IGraphics interface. However, in this case, your report won't rendered in PDF format.
          For example:
                 protected override void Draw(IGraphics gr, RectangleF rect, RectangleF parentRect) {
                     if(gr is GdiGraphics) {
                         (((GdiGraphics)gr)).Graphics.DrawEllipse(new Pen(this.Style.ForeColor), rect);
                     }
                 }
          Please feel free to contact us if you need any additional assistance. We will be happy to help you.
          Thanks,
          Andrew

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.