How to add custom control?

edited November 2008 in FastReport .NET
Hi,
I write a custom control MyTextObject inherited from TextObject, it does nothing only inherited base behavior,
then i register it. in designer, i drag and drop MyTextObject, set expression, like Text = "[MyTable.MyField]" , and preview, it's ok, everything is well.

But if i drag and drop another TextObject, and set it's Text an error expression, like Text = "[errortest]". when i preview, error message will display a namespace error in MyTextObject not in TextObject which is true error.

If i add my assembly in script's ReferenceAssemblies, error message will display correctly, but i have to add my assembly in every report.
Do you have a good idea?

thanks.

my code like following:

namespace MySoft.Report
{
public class MyTextObject: TextObject
{
}
}

//init
RegisteredObjects.Add(typeof(MyTextObject), "ReportPage", null, "MyText");

Comments

  • edited December 2008
    I also found a new problem associate with this, i add my assembly in script's ReferenceAssemblies,
    But if any expression in TextObject is error, I found my assembly in ReferenceAssemblies will be lost.
  • edited 10:03AM
    thinkdif wrote: »
    If i add my assembly in script's ReferenceAssemblies, error message will display correctly, but i have to add my assembly in every report.
    Do you have a good idea?

    If you have custom control, you have to add its assembly in every report that uses your control. I will try to simplify that in further builds.
  • edited 10:03AM
    How to add custom control?
    help me!
  • edited 10:03AM
    Please provide more info...
  • edited January 2009
    thanks,
    my code:
    public class MyButton : Button
    {
    public MyButton()
    {
    new Button();
    //this.Name= "button1";
    }
    }

    private void button1_Click(object sender, EventArgs e)
    {
    Bitmap bmp = (Bitmap)Bitmap.FromFile("C:\\alias.ico");
    FastReport.Utils.RegisteredObjects.Add(typeof(MyButton), "DialogPage", bmp, "Mybuttontext");
    report1.Design();
    }

    insert MyButton click on dialog form.
    problem: "NullReferenceException".
    Sorry bad english.
  • edited 10:03AM
    It's very difficult to describe every aspect of creation of own control. The best way is to see how standard controls are implemented (yes, you need FR.Net Pro with sources to do this). Here is a code of the standard LabelControl:
      /// <summary>
      /// Represents a standard Windows label.
      /// Wraps the <see cref="System.Windows.Forms.Label"/> control.
      /// </summary>
      public class LabelControl : DialogControl
      {
        private Label FLabel;
    
        #region Properties
        /// <summary>
        /// Gets an internal [b]Label[/b].
        /// </summary>
        [Browsable(false)]
        public Label Label
        {
          get { return FLabel; }
        }
    
        /// <summary>
        /// Gets or sets a value indicating whether the control is automatically resized to display its entire contents.
        /// Wraps the <see cref="System.Windows.Forms.Label.AutoSize"/> property.
        /// </summary>
        [DefaultValue(true)]
        [Category("Layout")]
        public bool AutoSize
        {
          get { return Label.AutoSize; }
          set { Label.AutoSize = value; }
        }
    
        /// <summary>
        /// Gets or sets the alignment of text in the label.
        /// Wraps the <see cref="System.Windows.Forms.Label.TextAlign"/> property.
        /// </summary>
        [DefaultValue(ContentAlignment.TopLeft)]
        [Category("Appearance")]
        public ContentAlignment TextAlign
        {
          get { return Label.TextAlign; }
          set { Label.TextAlign = value; }
        }
        #endregion
    
        #region Public Methods
        /// <inheritdoc/>
        public override void Serialize(FRWriter writer)
        {
          LabelControl c = writer.DiffObject as LabelControl;
          base.Serialize(writer);
    
          if (AutoSize != c.AutoSize)
            writer.WriteBool("AutoSize", AutoSize);
          if (TextAlign != c.TextAlign)
            writer.WriteValue("TextAlign", TextAlign);
        }
        #endregion
    
        /// <summary>
        /// Initializes a new instance of the [b]LabelControl[/b] class with default settings. 
        /// </summary>
        public LabelControl()
        {
          FLabel = new Label();
          Control = FLabel;
          
          Label.AutoSize = true;
        }
      }
    
  • edited 10:03AM
    my aim is adding a component like "lookupcombobox" in delphi which supports name and value pairs ,i.e which can get data from two fields to its name and value properties, then select using the name property and get the value field.

    Do you think adding it in later versions , or any ideas how can i achieve this ?

    thanks.
  • edited 10:03AM
    Maybe you will find the "data filtering" feature useful. Read about it in the user's manual ("Dialogue forms" chapter).
  • edited January 2009
    my aim is adding a component like "lookupcombobox" in delphi which supports name and value pairs ,i.e which can get data from two fields to its name and value properties, then select using the name property and get the value field.
    Do you think adding it in later versions , or any ideas how can i achieve this ?

    i'll use lookupcombo to construct an sql string
  • edited 10:03AM
    No, I'm not going to add this. You can use standard combobox control and write all necessary logic using the script.
  • edited 10:03AM
    combobox control "valueMamber" property not found!

  • edited 10:03AM
    See the User's manual, "Dialogue forms/Referencing to a control from code":


    In fact, the FastReport's control is just a wrapper for the standard .Net control. It wraps many, but not all, properties of the standard control. If you need some property that is not implemented by the FastReport control, you may access a wrapped standard control in the following way:

    ?· using the "Control" property, which is of System.Windows.Forms.Control type:

    (TextBox1.Control as TextBox).ShortcutsEnabled = false;

    ?· using the property which has the same name as the control itself, but without the "Control" suffix. For example, the TextBoxControl has got the "TextBox" property, which is of System.Windows.Forms.TextBox type and returns the wrapped TextBox control:

    TextBox1.TextBox.ShortcutsEnabled = false;

    Help on properties and methods of the controls can be accessed from the MSDN.
  • edited 10:03AM
    [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> Thanks. best regard[/img]

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.