ich habe ein UserControl erstellt, welches eigentlich nur aus den Control u. einem eingebettenen Button besteht.
Mit Hilfe dises Button will ich eine Tapi-Schnittstelle bedienen (aber das nur als grundsätzlicher Hinweis) --> das funktioniert auch alles wunderbar.
Was mich nur wahnsinnig stört ist, das, wenn ich das User Control auf eine WindowsForm ziehe, sehe ich nur folgendes (siehe Anhang UserControlDesigner01.jpg) :
eine Platzhalter für das Control der nicht verschoben werden kann.
Gehe ich mit dem Mauszeiger in eine der Ecken u. ändere durch ziehen die Größe des UserControls, so wird der Button plötzlich sichtbar, das Control ist jetzt da und kann auch verändert werden (siehe Anhang UserControlDesigner02.jpg).
Speichere ich die Form, schließe sie, u. öffne sie anschließend wieder, so ist es genauso wieder wie beim Einfügen der Controls in die Form.
Ich hab mir schon die Finger wundgegoogelt, aber leider nicht viel dazu gefunden; auch habe ich schon mit AutoSizeMode, Location, Locked, MaxSize, MinSize sowohl des Controls als auch des Button experimentiert aber leider ohne Erfolg, ebenso this.SetStyle
ich bin für jede Hilfe wirklick dankbar.
MfG ChrisPorg
hier mal der gesamte Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using JulMar.Atapi;
using System.CodeDom.Compiler;
namespace ATapiControl
{
[ToolboxBitmap(@"f:\VS-Programm\VS-Klassen\ATapi\ATapiControl\phone.bmp")]
[Description("Tool um eine Rufnummer per TAPI zu wählen \r\n" +
"(siehe \"Benutzung von ATapiControl.docx \" )")]
public partial class ATapiControlButton : UserControl
{
private string _rufnummer = String.Empty;
public string rufnummer
{ get; set; }
public string benutzer
{ get; set; }
TapiManager TapiPhone = new TapiManager("Phone.Net");
TapiLine activeLine = null;
TapiAddress activeNumber = null;
TapiCall tc = null;
Boolean iscalling = false, fuehrende_null = false;
Ini_Datei ini = new Ini_Datei(System.Windows.Forms.Application.StartupPath + "\\sql.ini");
string TapiGeraet = String.Empty, TapiNr = String.Empty;
public event EventHandler ATapiControlClick;
protected virtual void OnATapiControlClick(EventArgs e)
{
EventHandler myEvent = ATapiControlClick;
if (myEvent != null)
{ myEvent((this.Controls.Owner).Name, e); }
}
public ATapiControlButton()
{
InitializeComponent();
benutzer = "";
//this.SetStyle(ControlStyles.ContainerControl |
// ControlStyles.Opaque |
// ControlStyles.Selectable |
// ControlStyles.DoubleBuffer |
// ControlStyles.UserPaint |
// ControlStyles.AllPaintingInWmPaint |
// ControlStyles.SupportsTransparentBackColor |
// ControlStyles.ResizeRedraw, true);
this.BackColor = Color.Transparent;
}
private void ATapiControlButton_Load(object sender, EventArgs e)
{
#region TapiPhone
if (TapiPhone != null && TapiPhone.Initialize())
{
TapiGeraet = Environment.GetEnvironmentVariable("TapiLine", EnvironmentVariableTarget.User);
TapiNr = Environment.GetEnvironmentVariable("TapiNr", EnvironmentVariableTarget.User);
foreach (TapiLine line in TapiPhone.Lines)
{
if (TapiGeraet == String.Empty)
{
// Vorbelegung wenn noch nicht gespeichert
TapiGeraet = line.Name.ToString().Trim();
}
if (line.Name.ToString().Trim() == TapiGeraet)
{
activeLine = line;
line.CallStateChanged += this.OnCallStateChanged;
break;
}
}
if (activeLine != null)
{
foreach (TapiAddress x_adress in TapiPhone.Lines[activeLine.Id].Addresses)
{
if (TapiNr == String.Empty)
{
TapiNr = x_adress.ToString();
}
if (x_adress.ToString().Trim() == TapiNr)
{
activeNumber = x_adress;
}
}
}
}
else
{
MessageBox.Show("No Tapi devices found.");
this.Enabled = false;
}
#endregion
fuehrende_null = ini.Read("Tapi", "FührendeNullen", "Nein").ToUpper() == "JA";
this.Visible = (ini.Read("Tapi", "TapiFunktion", "OFF").ToUpper() == "ON") & darf_tapi_ermitteln();
}
private bool darf_tapi_ermitteln()
{
if (benutzer.Trim() == String.Empty)
return true;
Boolean darf_tapi = false;
SQL_login sqllogin = new SQL_login();
SqlCommand command = new SqlCommand("SELECT tapi_kz FROM d001000 WHERE benutzer = '" + benutzer.Trim() + "'", sqllogin.connection_SQL());
SqlDataReader r_d001001 = null;
try
{
r_d001001 = command.ExecuteReader();
if (r_d001001.Read())
{
darf_tapi = r_d001001.GetBoolean(0);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (!r_d001001.IsClosed)
{
r_d001001.Close();
}
r_d001001.Dispose();
}
return darf_tapi;
}
public void anrufen()
{
#region nicht-Zahlen entfernen
String pruef_rufnummer = rufnummer;
rufnummer = String.Empty;
for (int i = 0; i < pruef_rufnummer.Length; i++)
{
if ((int)Convert.ToChar(pruef_rufnummer[i].ToString()) ≥ 48 && (int)Convert.ToChar(pruef_rufnummer[i].ToString()) ≤ 57)
{
rufnummer += pruef_rufnummer[i];
}
}
#endregion
if (rufnummer != null && rufnummer.Trim() != String.Empty)
{
if (fuehrende_null)
{
if (!rufnummer.StartsWith("00"))
{ rufnummer = "0" + rufnummer; }
}
if (iscalling)
{
if (!(tc.CallHandle).IsClosed)
{
tc.Drop();
}
iscalling = false;
make_call.BackgroundImage = Properties.Resources.hoerer_gruen_klein;
if (CurrentLine.IsOpen)
{
line_start_stop();
}
}
else
{
if (!CurrentLine.IsOpen)
{
line_start_stop();
}
try
{
tc = CurrentAddress.MakeCall(rufnummer);
iscalling = true;
make_call.BackgroundImage = Properties.Resources.hoerer_rot_klein;
}
catch (TapiException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
#region Prozeduren für TapiPhone
TapiLine CurrentLine
{
get
{
return activeLine;
}
}
TapiAddress CurrentAddress
{
get
{
return (TapiAddress)activeNumber;
}
}
#endregion
private void line_start_stop()
{
TapiLine line = CurrentLine;
if (line.IsOpen)
{
line.Close();
}
else
{
try
{
line.Open(line.Capabilities.MediaModes);
}
catch (TapiException)
{
line.Open(MediaModes.DataModem);
}
}
}
private void OnCallStateChanged(object sender, CallStateEventArgs e)
{
if (this.InvokeRequired)
{
EventHandler<CallStateEventArgs> eh = OnCallStateChanged;
this.BeginInvoke(eh, new object[] { sender, e });
return;
}
TapiLine line = (TapiLine)sender;
TapiCall call = e.Call;
if (call.CallState == CallState.Idle)
{
call.Dispose();
if ((call.CallHandle).IsClosed)
{
make_call.BackgroundImage = Properties.Resources.hoerer_gruen_klein;
iscalling = false;
if (CurrentLine.IsOpen)
{
line_start_stop();
}
}
}
}
private void make_call_Click(object sender, EventArgs e)
{
OnATapiControlClick(EventArgs.Empty);
anrufen();
}
public void PerformClick(string x_rufnummer)
{
rufnummer = x_rufnummer;
anrufen();
}
}
}