I have created a Form using c++ (CLR).
I have added a richtextbox and I need to make it visible in my source file in order to change the text from there.
So to sum it up:
I have a richtextbox in MyForm.h.I need to change the text of this richtextbox from Source.cpp.How do I do that?
Managed to fix it by doing so:
Creating a new function in the .cpp source file like this:
void TEST(System::Windows::Forms::RichTextBox ^ changin)
{
changin->Text = "TEST";
}
Than in the .h file
void TEST(System::Windows::Forms::RichTextBox ^ changin);
Here is when a button is pushed:
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
TEST(richTextBox4);
}
Where richTextBox4 is the one that should be modified from the .cpp file.
Pass your text through a public function in your form and there update the text.
In such way you save object encapsulation.
In your form add a method in the following manner:
In the form you have a private field:
private RichTextBox rtb;
rtb is reference to a user control containing the RichTextBox which expose the RichTextBox text property by overriding it:
public override string Text
{
get
{
return rtb.Text;
}
set
{
rtb.Text = value;
}
}
then by a public method in your form you can access the RichTextBox.
public void SetText()
{
rtb.Text = "test_text";
}
you can have a look on the same idea here:
http://www.codeproject.com/Articles/18178/A-Padded-Text-Box-Control
Update : have a look on the following example it emphasize my explanation above : http://www.codeproject.com/Articles/4544/Insert-Plain-Text-and-Images-into-RichTextBox-at-R
I hope it is clear enough.
Related
When I put this control on to a form, change it's size and location, save it and close the form. After opening it, location and size are not the same, but in ".Designer.cs" it's exactly how I set it.
I can't find a solution to this problem, not even someone mentioning it.
This is a simple example of a custom control I am using:
[Designer(typeof(myControlDesigner1))]
public partial class UserControl1 : UserControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TypeConverter(typeof(Panel))]
[MergableProperty(false)]
public System.Windows.Forms.Panel Panel
{
get
{
return pnlWorkingArea;
}
set
{
pnlWorkingArea = value;
}
}
public UserControl1()
{
InitializeComponent();
}
}
public class myControlDesigner1 : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
UserControl1 bc = component as UserControl1;
EnableDesignMode(bc.Panel, "MyPanel");
}
}
Yes I can reproduce your issue now, that is because the panel is inside usercontrol, they are added as a whole to the Form, that means the location of the panel is relative to usercontrol, so if you set the location of the panel is (x, y), then when you reopen the form, the actual location of the panel will be (usercontrol.location.X+x, usercontrol.location.Y+y).
You can find there is not any problem if you set the location of the usercontrol in the form is (0, 0), please have a try.
If you do not want to set the location of the usercontrol is (0, 0), as an alternative solution, you can add the following code in Form_Load event, so the location will be where you set it when you run the form:
private void Form1_Load(object sender, EventArgs e)
{
this.userControl11.Panel.Location = new Point(userControl11.Panel.Location.X - userControl11.Location.X, userControl11.Panel.Location.Y - userControl11.Location.Y);
}
Whether I try to change a textView or a button, why does Android Studio require that I pass only chars and not strings in the setText() method?
Strings are automatically converted to CharSequences when necessary (or are CharSequences; can't remember. The point is, they're compatible):
public class Main {
public static void testF(CharSequence seq) {
System.out.println(seq);
}
public static void main(String[] args) {
testF("Hello"); // Prints "Hello"
}
}
This would have been a good thing to try on your own or search for first.
private void Form1_Load(object sender, EventArgs e)
{
AutoCompleteStringCollection nc = new AutoCompleteStringCollection();
nc.AddRange(new string[]
{
"boston",
"sanfransisco"
});
textBox1.AutoCompleteCustomSource = nc;
textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
Autocomplete isn't working and I don't know why. If I add more strings to the array they still don't show up and I've tried moving new AutoCompleteStringCollection() out of the private method. I have the properties set the same way in the form properties too.
Do you have to import something for AutoCompleteMode to work?
From the documentation on AutoCompleteSource you can find this note
AutoCompleteSource does not work on multiline TextBox controls.
So you could only switch to a MultiLine=false to have your code to work.
Searching on the NET there are various solutions that give to a multiline textbox the functionality of AutoComplete, but they always include some tweaking on the PreviewKeyDown method
I have a static text named IDC_STATIC for which I made a click event, but it is not getting called when it's clicked.
ON_BN_CLICKED(IDC_STATIC, ontest) //(begin message map)
void test::ontest(my method)
{
MessageBox("success");
}
afx_msg void test(); //(header file)
What is wrong with the code?
The solution is to go to the static text control's properties and enable Notify.
There is a program that I am working on and Im absolutly lost even at how to begin this. I am using Visual Studio C# Windows App Form.
What I need to do is allow the user to enter any path location they want and the program will return the Name of the file/folder; Path; date and size, and this will also be done for sub directories.
I found some code in the MSDN site and I am trying to use it and modify it for the first part of this project, but keep receiving error messages. Some of the messages indicate that there is more than one entry ie (static void Main() and using namespace Detailed).
This is what I have so far, a form with rich text box and the FolderBrowserDialog and it seems as I can't get beyond this point without so many errors.
This is under Form1.Designer.cs:
<i>namespace Detailed
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(12, 32);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(167, 23);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}
For the For1.cs this is what I have so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class FolderBrowserDialogExampleForm : System.Windows.Forms.Form
{
private FolderBrowserDialog folderBrowserDialog1;
private OpenFileDialog openFileDialog1;
private RichTextBox richTextBox1;
private MainMenu mainMenu1;
private MenuItem fileMenuItem, openMenuItem;
private MenuItem folderMenuItem, closeMenuItem;
private string openFileName, folderName;
private bool fileOpened = false;
public partial class Form1 : Form
{
public Form1()
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// FolderBrowserDialogExampleForm
//
this.ClientSize = new System.Drawing.Size(284, 262);
this.Name = "FolderBrowserDialogExampleForm";
this.ResumeLayout(false);
}
}
I'm still new to programing and hope I can get this figured out asap as I was requested to have this no later than Thursday morning est. I had the Rich TextBox in the Form, but removed it because of too many errors.
This is the code I found. I know this is just part of what I need to do, but when reading through the code I noticed that maybe I can apply what is needed to the form and then break up the code and put the pieces of code where I need them. This is the code I am following
Here is an error message I am receiving with Form1.Designer.cs - there are 14 of these same errors:
‘Detailed.form1’ does not contain a definition for ‘Form1_Load’ and no extension method ‘Form1_Load’ accepting a first argument of type ‘Detailed.Form1’ could be found (are you missing a using directive or an assembly reference?)
The first thing you want is a dialog prompting the user for a directory.
So get rid of all that code, start a new project win form and place a textbox in your form and a button in your form.
Simple enough one text box and one button. Now in the click event of your button "Browse", have you, you write code to open an instance of the FolderBrowserDialog class and you .ShowDialog().
To get this path:
Here is a sample screen output:
The code is fairly straightforward, look at my picture and how much code i have to do this.