Hi, folks.
I created a UserControl to have some buttons availabe in a form. These buttons control automatically their enable property, and it's workin fine. I wanted to make it more sophisticated, so I included a tip, so as when the user passes the cursor over the button, it shows the tip. This is working partially, because when I change the tip text in the form where I included this user control, it ignores the change. It always use the default text I included in the user control. The code (simplified) is showed below.
Also, lines 22 and 23, where I define the defalt tips are in a light colour, and VS indicates there is something wrong, but I can't find it. Can anyone help me? What is wrong in my code?
Thank you.
I created a UserControl to have some buttons availabe in a form. These buttons control automatically their enable property, and it's workin fine. I wanted to make it more sophisticated, so I included a tip, so as when the user passes the cursor over the button, it shows the tip. This is working partially, because when I change the tip text in the form where I included this user control, it ignores the change. It always use the default text I included in the user control. The code (simplified) is showed below.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GestaoLav
{
public partial class Botoes : UserControl
{
public Botoes()
{
InitializeComponent();
TipNovo.SetToolTip(this.bt_Novo, _DicaNovo);
TipSalvar.SetToolTip(this.bt_Salvar, _DicaSalvar);
}
private bool _EmEdicao = false;
private string _DicaNovo = "Cria um registro";
private string _DicaSalvar = "Salva os dados do novo registro";
public string DicaNovo
{
get => _DicaNovo;
set
{
_DicaNovo = value;
}
}
public string DicaSalvar
{
get => _DicaSalvar;
set
{
_DicaSalvar = value;
}
}
public bool EmEdicao
{
get => _EmEdicao;
set
{
_EmEdicao = value;
bt_Novo.Enabled = !_EmEdicao;
bt_Editar.Enabled = !_EmEdicao;
bt_Apagar.Enabled = !_EmEdicao;
bt_Salvar.Enabled = _EmEdicao;
bt_Cancelar.Enabled = _EmEdicao;
}
}
public event EventHandler NovoClicked;
public event EventHandler SalvarClicked;
private void NovoButton_Click(object sender, EventArgs e)
{
NovoClicked?.Invoke(this, e);
EmEdicao = true;
}
private void SalvarButton_Click(object sender, EventArgs e)
{
SalvarClicked?.Invoke(this, EventArgs.Empty);
EmEdicao = false;
}
}
}
Thank you.