Go Back   TX Text Control Community > TX Text Control Discussion and Support Forums > TX Text Control .NET Server

TX Text Control .NET Server Please use this forum for TX Text Control .NET Server support only. If you need support for a different product, please use the appropriate forum.

Reply
 
Thread Tools Display Modes
  #1  
Old February 11, 2010
scaulfield scaulfield is offline
Registered User
 
Join Date: Sep 2009
Posts: 9
Exclamation NullReferenceException after inserting Image in Header

Hi,

I seem to be having an issue with the BrowserTextControl (version 15.1), when I add an image to the header or footer, I get a null refernece exception originating from the txkernel.

If I change the code to deactivate the header after inserting the image an exception is not thrown. However, if I reactivate the header then the same exception is thrown.

The stack trace does not give any particularly useful information (I have included a screenshot as an attachment).

Here is my code:

Code:
private void tsbAddImage_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = browserTextControl1.Images.ImportFilters;
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                TXTextControl.Image img = new TXTextControl.Image(openFileDialog1.FileName, openFileDialog1.FilterIndex);
                img.ExportFilterIndex = openFileDialog1.FilterIndex;
                img.SaveMode = ImageSaveMode.SaveAsData;

                if (activePagePart == ActivePart.HEADER)
                {
                    HeaderFooter hf = browserTextControl1.HeadersAndFooters.GetItem(HeaderFooterType.Header);
                    hf.Images.Add(img, -1);
                    hf.Deactivate();
                }
                else if (activePagePart == ActivePart.FOOTER)
                {
                    HeaderFooter hf = browserTextControl1.HeadersAndFooters.GetItem(HeaderFooterType.Footer);
                    hf.Images.Add(img, -1);
                    hf.Deactivate();
                }
                else
                {
                    browserTextControl1.Images.Add(img, -1);
                }
                
            }
        }
Thanks for any help
Attached Images
File Type: png Capture.PNG (40.8 KB, 16 views)
Reply With Quote
  #2  
Old February 11, 2010
Gunnar Giffey's Avatar
Gunnar Giffey Gunnar Giffey is offline
TX Support Engineer
TX Text Control
 
Join Date: Sep 2004
Location: Bremen, Germany
Posts: 3,999
Re: NullReferenceException after inserting Image in Header

Hello there,
Although you are using version 15.1, you do not seem to use sections, which have to be used to access header and footers:
http://www.textcontrol.com/en_US/sup...ories.page.htm
Not sure if that is the cause for your exception as I can not run your code (what is activePagePart?).
If you supply simpler code or a working sample, I will gladly take a look at your issue.
__________________
Regards,
Gunnar Giffey, TX Text Control
[Forum Administrator]
Reply With Quote
  #3  
Old February 16, 2010
scaulfield scaulfield is offline
Registered User
 
Join Date: Sep 2009
Posts: 9
Re: NullReferenceException after inserting Image in Header

Hi,

Just as a general point, is there any special approach which needs to be taken to insert an image into a header (assuming that the header is active and the image is being inserted at the current text position).

I am using code along the lines of:

Code:
    browserTextControl1.Images.Add(img, -1);
Which I was assuming would detect the current input position and insert an image into the correct collection, or am I wrong about this.

Thanks

Stephen
Reply With Quote
  #4  
Old February 16, 2010
scaulfield scaulfield is offline
Registered User
 
Join Date: Sep 2009
Posts: 9
Re: NullReferenceException after inserting Image in Header

I have made a very simple example for investigation:

Created in VS2008 with .NET v2.0

Designer Code:

Standard TXControl Setup (ButtonBar, Rulers, StatusBar) with one
ToolStripContainer, containing one ToolstripButton called tsbAddImage.
tsbAddImage has a Click event handler tsbAddImage_Click.

The form uses the code below:


Code:
namespace WordProcessor
{
    public partial class BrowserAppControl : UserControl
    {
        public BrowserAppControl()
        {
            InitializeComponent();
            browserTextControl1.ButtonBar = browserButtonBar1;
            browserTextControl1.RulerBar = browserRulerBar1;
            browserTextControl1.VerticalRulerBar = browserRulerBar2;
            browserTextControl1.StatusBar = browserStatusBar1;
            browserTextControl1.ViewMode = TXTextControl.ViewMode.PageView;
            browserTextControl1.CreateControl();
        }

        private void tsbAddImage_Click(object sender, EventArgs e)
        {
            HeaderFooter header = null;
            if (browserTextControl1.Sections.GetItem().HeadersAndFooters.GetItem(HeaderFooterType.Header) != null)
            {
                header = browserTextControl1.Sections.GetItem().HeadersAndFooters.GetItem(HeaderFooterType.Header);
            }
            else
            {
                browserTextControl1.Sections.GetItem().HeadersAndFooters.Add(HeaderFooterType.Header);
                header = browserTextControl1.Sections.GetItem().HeadersAndFooters.GetItem(HeaderFooterType.Header);

            }
            header.Activate();
            browserTextControl1.HeaderFooterActivationStyle = HeaderFooterActivationStyle.ActivateClick;
            browserTextControl1.HeaderFooterFrameStyle = HeaderFooterFrameStyle.DottedFrame;

            TXTextControl.Image img = new TXTextControl.Image();
            header.Images.Add(img, -1);
               

        }
    }
}
Thanks for the help

Cheers

Stephen
Reply With Quote
  #5  
Old February 16, 2010
Gunnar Giffey's Avatar
Gunnar Giffey Gunnar Giffey is offline
TX Support Engineer
TX Text Control
 
Join Date: Sep 2004
Location: Bremen, Germany
Posts: 3,999
Re: NullReferenceException after inserting Image in Header

Hello Stephen,
Thanks your for your reply.
Could you please attach the full project, so I can run that here to debug it?
You can simply attach it to your post if you zip up the project folder.
Thanks.
__________________
Regards,
Gunnar Giffey, TX Text Control
[Forum Administrator]
Reply With Quote
  #6  
Old February 16, 2010
scaulfield scaulfield is offline
Registered User
 
Join Date: Sep 2009
Posts: 9
Re: NullReferenceException after inserting Image in Header

Hi Gunnar,

Please find attached an example project.

I have removed all of the standard TXControl dlls and associated files from the BrowserBin directory to minimize the file size

Thanks

Stephen
Attached Files
File Type: zip WordProcessingWeb.zip (46.8 KB, 19 views)
Reply With Quote
  #7  
Old February 16, 2010
Gunnar Giffey's Avatar
Gunnar Giffey Gunnar Giffey is offline
TX Support Engineer
TX Text Control
 
Join Date: Sep 2004
Location: Bremen, Germany
Posts: 3,999
Re: NullReferenceException after inserting Image in Header

Stephen,
I can run and insert an image using your sample project without any exception.
Are you able to reproduce the error on your development machine or client PC?
__________________
Regards,
Gunnar Giffey, TX Text Control
[Forum Administrator]
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Image ShitalP TX Text Control .NET 1 April 24, 2009 13:34:30
Inserting Image in Textcontrol Gnanaprakash TX Text Control .NET 2 December 16, 2008 13:23:17
Inserting an Image reezel TX Text Control .NET 7 September 5, 2008 13:25:21
After inserting an image, pb to leave blank lines after that image sebmay TX Text Control .NET 4 June 16, 2008 15:53:53
Problem Inserting Fixed Image peals97 TX Text Control ActiveX 1 June 21, 2006 11:46:36


All times are GMT +1. The time now is 06:18:28.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 1991 - 2010 The Imaging Source Europe GmbH