Autor Beitrag
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 05.04.17 07:47 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: tomycat
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 05.04.17 09:25 
Hallo tomycat,

selbstverständlich muß die Datei, in der der Code für die AutoCompleteTextBox drin ist, Teil des Projektes sein (eben über "Datei->Neue Datei"), also im Solution-Explorer auftauchen (alternativ natürlich in einer eigenen Assembly und per Referenz ins Projekt eingebunden).

Solange derselbe Namensbereich (namespace) wie die Applikation benutzt wird, ist auch kein using nötig - und wenn man den Designer (ToolBox) benutzt, dann kümmert sich dieser auch um den richtigen Namensbereich beim Codeerzeugen.

PS: Hier noch ein Tutorial: Creating Custom Controls In C#

Für diesen Beitrag haben gedankt: tomycat
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 05.04.17 12:24 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 05.04.17 16:40 
hmmmmmm

ich habe die class1.cs hinzugefügt:

Projektmappe "AutoCompleteSample" (Projekt1)
Solution Items
Class1.cs
AutoCompleteSample
Properties
Verweise
Form1.cs
Program.cs

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
using System;

//public class Class1
//{
   // public Class1()
   // {
  //  }
            public class AutoCompleteTextBox : TextBox
    {
        private ListBox _listBox;
        private bool _isAdded;
        private String[] _values;
        private String _formerValue = String.Empty;


Irgendwo mache ich einen Denkfehler?!
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 05.04.17 16:47 
Class1.cs muß zu einem Projekt gehören nicht zur Projektmappe. Hinter einer Projektmappe steht nichtst was kompiliert wird. Die Projekte in der Projektmappe werden kompiliert die Mappe ist nur eine Verwaltungsklammer. Deine class1.cs muß aber kompiliert werden sonst ist da nix was ausgeführt werden kann. Genauso wie Programm.cs und Form1.cs gehört die also in ein Projekt. Solutions Items kannst du für dokumentarische Zwecke nutzen für dich als Entwickler. Das Zeug landet aber nicht in der kompilierten Anwendung.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 06.04.17 10:45 
@Ralf Jansen
vielen Dank, deine Worte sind Goldwert.
in der Class1.cs habe ich die using von Hauptprojekt eingefügt.

Ich habe noch ein kleines weiteres Problem
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AutoCompleteSample
{
    public partial class Form1 : Form
    {
        private readonly String[] _values = { "one""two""three""tree""four""fivee" }; //neu

        public Form1()
        {
            InitializeComponent();
            AutoComplete.Values = _values; //neu....AutoComplete <--- ist Rot.
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; 
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            AutoCompleteStringCollection data = new AutoCompleteStringCollection();
            data.Add("Mahesh Chand");
            comboBox1.AutoCompleteCustomSource = data;           
        }
    }
}



Der Name AutoComplete ist im Kontext nicht vorhanden.
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 06.04.17 11:46 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Fr 07.04.17 13:22 
thx, aber ich habe irgendwo den Faden verloren.


user profile iconFrühlingsrolle hat folgendes geschrieben Zum zitierten Posting springen:
Ist AutoComplete ein Objekt von der Klasse AutoCompleteTextBox? Wenn ja, wo wird es erzeugt?


oohh, eigentlich nicht-

user profile iconFrühlingsrolle hat folgendes geschrieben Zum zitierten Posting springen:
Ist im Code nicht ersichtlich.


Quelle:
stackoverflow.com/qu...-middle-of-a-textbox

Aber in dem Beispiel geht vor...
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
using System;
using System.Windows.Forms;

namespace AutoComplete
{
    public partial class TestForm : Form
    {
        private readonly String[] _values = { "one""two""three""tree""four""fivee" };

        public TestForm()
        {
            InitializeComponent();
            // AutoComplete is our special textbox control on the form
            AutoComplete.Values = _values;
        }

    }
}

Was will der Programmierer damit ausdrücken, wenn AutoComplete in der Luft hängt?
Wo soll ich das Stück Code einbauen?
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Fr 07.04.17 13:33 
Wie stehts um dein english?

In dem Kommentar steht
Zitat:
// AutoComplete is our special textbox control on the form

Du hast diese Combox scheinbar comboBox1 genannt. Also ersetze den Namen von comboBox1 durch AutoComplete oder den Bezeichner AutoComplete an der Stelle durch comboBox1.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Fr 07.04.17 13:53 
user profile iconRalf Jansen hat folgendes geschrieben Zum zitierten Posting springen:
Wie stehts um dein english?

so lala :-)

user profile iconRalf Jansen hat folgendes geschrieben Zum zitierten Posting springen:

In dem Kommentar steht
Zitat:
// AutoComplete is our special textbox control on the form

Du hast diese Combox scheinbar comboBox1 genannt. Also ersetze den Namen von comboBox1 durch AutoComplete oder den Bezeichner AutoComplete an der Stelle durch comboBox1.


Nein, Combobox1 ist etwas zum testen es hat nichts mit diese speziellen Textbox zutun :-)
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Fr 07.04.17 14:01 
ok, habs umbenannt.
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
 comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; 
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            AutoCompleteStringCollection data = new AutoCompleteStringCollection();
            data.Add("Mahesh Chand");
            comboBox1.AutoCompleteCustomSource = data;

           // autoCompleteTextBox1
            autoCompleteTextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            autoCompleteTextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
     //     AutoCompleteStringCollection data = new AutoCompleteStringCollection();
            data.Add("Mahesh Chand");
            autoCompleteTextBox1.AutoCompleteCustomSource = data;


Aber er macht NUR am Zeilenanfang die Autovervollständigung. Nicht mitten im Satz.
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Fr 14.04.17 20:31 
Planänderung, bevor ich weiter an dem Code herummache, der vielleicht sowieso nicht geht :-)
Also baue ich dem Kram selber. Wenn jemand einen Code sucht, der Mittendrin nach 1,2,3,4 oder 5 Zeichen sucht und die Wörter vervollständigt, bitte sehr:

Die Löschtaste musste abgefangen werden, weil man sich im Kreis bewegt. Einfach mit der Maus makieren und löschen.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        string[] lex = new string[] { "one""two""three" };
        string ergebnis;
        public Form1()
        {
            InitializeComponent();
           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int begrifflaenge = textBox1.SelectionStart;
            string schluesselwort = "";
            string tmp = textBox1.Text;
            string mein_ergebnis;
            int courserpos_tmp = textBox1.SelectionStart;
            ///////////////////////////////////////////////////////////////////
            // Nach einem Zeichen Suchen:
            if (courserpos_tmp == 1)
                if (tmp.Substring(01) != " ")
                {
                   
                    schluesselwort = tmp.Substring(01);
                    begrifflaenge = 1;
                    Console.WriteLine("1 zeichen, Anfang" + " -->>" + schluesselwort);
                }
            // Nach einem Zeichen Suchen:
            if (tmp.Length > 1 && tmp.Substring(tmp.Length - 21) == " " && tmp.Substring(tmp.Length - 11) != " ")
            {
      
                schluesselwort = tmp.Substring(tmp.Length - 11);
                begrifflaenge = 1;
                Console.WriteLine("1 zeichen, Mittendrin" + " -->>" + schluesselwort);
            }
            ////////////////////////////////////////////////////////////////////

            // Nach 2 Zeichen Suchen:
            if (courserpos_tmp == 2)
                if (tmp.Substring(01) != " " && tmp.Substring(11) != " ")
                {
                  
                    schluesselwort = tmp.Substring(01) + tmp.Substring(11);
                    begrifflaenge = 2;
                  //  Console.WriteLine(schluesselwort);
                    Console.WriteLine("2 zeichen, Anfang" + " -->>"+ schluesselwort);
                   
                }
            // Nach 2 Zeichen Suchen:
            if (tmp.Length > 2 && tmp.Substring(tmp.Length - 31) == " " && tmp.Substring(tmp.Length - 21) != " " && tmp.Substring(tmp.Length - 11) != " ")
            {
   
                schluesselwort = tmp.Substring(tmp.Length - 21) + tmp.Substring(tmp.Length - 11);
                begrifflaenge = 2;
                Console.WriteLine("2 zeichen, Mittendrin" + " -->>" + schluesselwort);
            }
            /////////////////////////////////////////////////////////////////////
            // Nach 3 Zeichen Suchen:
            if (courserpos_tmp == 3)
                if (tmp.Substring(01) != " " && tmp.Substring(11) != " " && tmp.Substring(21) != " ")
                {
         
                    schluesselwort =  tmp.Substring(01) +tmp.Substring(11) + tmp.Substring(21);
                        begrifflaenge = 3;
                    Console.WriteLine("3 zeichen, Anfang" + " -->>" + schluesselwort);
                }
            // Nach 2 Zeichen Suchen:
            if (courserpos_tmp > 3 && tmp.Substring(tmp.Length - 41) == " " && tmp.Substring(tmp.Length - 31) != " " && tmp.Substring(tmp.Length - 21) != " " && tmp.Substring(tmp.Length - 11) != " ")
            {
               
                //   Console.WriteLine("-" + tmp.Substring(tmp.Length - 3, 2) + "+");
                schluesselwort = tmp.Substring(tmp.Length - 31) + tmp.Substring(tmp.Length - 21) + tmp.Substring(tmp.Length - 11);
                  begrifflaenge = 3;
                Console.WriteLine("3 zeichen, Mittendrin" + " -->>" + schluesselwort);
            }
            /////////////////////////////////////////////////////////////////////
            // Nach 4 Zeichen Suchen:
            if (courserpos_tmp == 4)
                if (tmp.Substring(01) != " " && tmp.Substring(11) != " " && tmp.Substring(21) != " " && tmp.Substring(31) != " ")
                {
                 
                    schluesselwort = tmp.Substring(01) + tmp.Substring(11) + tmp.Substring(21) + tmp.Substring(31);
                    begrifflaenge = 4;
                    Console.WriteLine("4 zeichen, Anfang" + " -->>" + schluesselwort);
                }
            // Nach 4 Zeichen Suchen:
            if (courserpos_tmp > 4 && tmp.Substring(tmp.Length - 51) == " " && tmp.Substring(tmp.Length - 41) != " " && tmp.Substring(tmp.Length - 31) != " " && tmp.Substring(tmp.Length - 21) != " " && tmp.Substring(tmp.Length - 11) != " ")
            {

                //   Console.WriteLine("-" + tmp.Substring(tmp.Length - 3, 2) + "+");
                schluesselwort = tmp.Substring(tmp.Length - 41) + tmp.Substring(tmp.Length - 31) + tmp.Substring(tmp.Length - 21) + tmp.Substring(tmp.Length - 11);
                begrifflaenge = 4;
                Console.WriteLine("4 zeichen, Mittendrin" + " -->>" + schluesselwort);
            }
            /////////////////////////////////////////////////////////////////////
            // Nach 5 Zeichen Suchen:
            if (courserpos_tmp == 5)
                if (tmp.Substring(01) != " " && tmp.Substring(11) != " " && tmp.Substring(21) != " " && tmp.Substring(31) != " " && tmp.Substring(41) != " ")
                {
                   
                    schluesselwort = tmp.Substring(01) + tmp.Substring(11) + tmp.Substring(21) + tmp.Substring(31) + tmp.Substring(41);
                    begrifflaenge = 5;
                    Console.WriteLine("5 zeichen, Anfang" + " -->>" + schluesselwort);
                }
            // Nach 5 Zeichen Suchen:
            if (courserpos_tmp > 5 && tmp.Substring(tmp.Length - 61) == " " && tmp.Substring(tmp.Length - 51) != " " && tmp.Substring(tmp.Length - 41) != " " && tmp.Substring(tmp.Length - 31) != " " && tmp.Substring(tmp.Length - 21) != " " && tmp.Substring(tmp.Length - 11) != " ")
            {

                //   Console.WriteLine("-" + tmp.Substring(tmp.Length - 3, 2) + "+");
                schluesselwort = tmp.Substring(tmp.Length - 51) + tmp.Substring(tmp.Length - 41) + tmp.Substring(tmp.Length - 31) + tmp.Substring(tmp.Length - 21) + tmp.Substring(tmp.Length - 11);
                begrifflaenge = 4;
                Console.WriteLine("5 zeichen, Mittendrin" + " -->>" + schluesselwort);
            }
            /////////////////////////////////////////////////////////////////////


            switch (begrifflaenge)           
            {
                case 1:            
                    mein_ergebnis = seach_the_word(schluesselwort, 1);
                    if (ergebnis.Length != 0)
                    {
                        textBox1.Text += mein_ergebnis.Substring(1, ergebnis.Length - 1);
                        textBox1.Select(courserpos_tmp, textBox1.TextLength);
                    }
                    textBox1.SelectionStart = courserpos_tmp;
                    break;
                case 2:             
                    mein_ergebnis = seach_the_word(schluesselwort,2);
                    if (ergebnis.Length != 0)
                    {
                        textBox1.Text += mein_ergebnis.Substring(2, ergebnis.Length - 2);
                        textBox1.Select(courserpos_tmp, textBox1.TextLength);
                    }
                    textBox1.SelectionStart = courserpos_tmp;
                    break;
                case 3:              
                    mein_ergebnis = seach_the_word(schluesselwort, 3);
                    if (ergebnis.Length != 0)
                    {
                        textBox1.Text += mein_ergebnis.Substring(3, ergebnis.Length - 3);
                        textBox1.Select(courserpos_tmp, textBox1.TextLength);
                    }
                    textBox1.SelectionStart = courserpos_tmp;
                    break;
                case 4:     
                    mein_ergebnis = seach_the_word(schluesselwort, 4);
                    if (ergebnis.Length != 0)
                    {
                        textBox1.Text += mein_ergebnis.Substring(4, ergebnis.Length - 4);
                        textBox1.Select(courserpos_tmp, textBox1.TextLength);
                    }
                    textBox1.SelectionStart = courserpos_tmp;
                    break;
                case 5:
                    mein_ergebnis = seach_the_word(schluesselwort, 5);
                    if (ergebnis.Length != 0)
                    {
                        textBox1.Text += mein_ergebnis.Substring(5, ergebnis.Length - 5);
                        textBox1.Select(courserpos_tmp, textBox1.TextLength);
                    }
                    textBox1.SelectionStart = courserpos_tmp;
                    break;
            }


        }
        string seach_the_word(string a, int laenge)
        {
            ergebnis = "";
            for (int xy =0 ;xy < 3;xy++)
            {
                if (lex[xy].Length >= laenge)
                {
                    if (a == lex[xy].Substring(0, laenge))
                    {
                        ergebnis = (lex[xy]);
                    }
                }

            }
            Console.WriteLine(ergebnis);
            return (ergebnis);
        }
    }
}
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 14.04.17 21:04 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Sa 15.04.17 19:51 
Aufgeben = verlieren
nicht aufgeben führt oft zu freude und stolz. :-)

Die Backspacetaste macht mir noch Kummer, sie geht nicht. Bei jeder Veränderung wird automatisiert. Hätte jemand eine Idee?
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 15.04.17 21:08 
- Nachträglich durch die Entwickler-Ecke gelöscht -

Für diesen Beitrag haben gedankt: tomycat