C# Focus bei UserControl?

Hallo,

ich hab ein Problem mit dem Focus eines UserControls. Und zwar bekommt das UserControl trotzdem den Focus obwohl alle seine ChildControls nicht focusierbar sind. Ich hab hier mal ein kleines Beispiel erstellt, zum testen einfach ein neues Windows Forms Project anlegen und den Code in den Source Code der Form kopieren.

using System.Windows.Forms;

namespace testUserControl
{
  using System.Diagnostics.Eventing.Reader;

  public partial class Form1 : Form
  {
    private testControl testControl1;
    private testControl testControl2;
    private testControl testControl3;
    
    public Form1()
    {
      InitializeComponent();

      this.testControl1 = new testUserControl.testControl();
      this.testControl2 = new testUserControl.testControl();
      this.testControl3 = new testUserControl.testControl();

      this.testControl1.Location = new System.Drawing.Point(24, 27);
      this.testControl1.Name = "testControl1";
      this.testControl1.Size = new System.Drawing.Size(150, 37);
      this.testControl1.TabIndex = 0;


      this.testControl2.Location = new System.Drawing.Point(24, 71);
      this.testControl2.Name = "testControl2";
      this.testControl2.Size = new System.Drawing.Size(150, 45);
      this.testControl2.TabIndex = 1;


      this.testControl3.Location = new System.Drawing.Point(24, 136);
      this.testControl3.Name = "testControl3";
      this.testControl3.Size = new System.Drawing.Size(150, 47);
      this.testControl3.TabIndex = 2;

      this.Controls.Add(this.testControl3);
      this.Controls.Add(this.testControl2);
      this.Controls.Add(this.testControl1);

      testControl2.Disable();
    }
  }

  public class testControl : UserControl
  {
    private TextBox test;

    private Label TestLabel;

    public testControl()
    {
      this.test = new TextBox();
      this.test.Name = "TextBox";
      this.test.Location = new System.Drawing.Point(100, 5);
      this.test.Size = new System.Drawing.Size(80, 17);

      this.TestLabel = new Label();
      this.TestLabel.Name = "Label";
      this.TestLabel.Text = "Test";
      this.TestLabel.Location = new System.Drawing.Point(10, 5);
      this.TestLabel.Size = new System.Drawing.Size(50, 17);

      this.Controls.Add(this.test);
      this.Controls.Add(this.TestLabel);
    }

    public void Disable()
    {
      this.test.Enabled = false;
    }
  }
}

Ich weiß das das Design jetzt nicht schön aussieht aber das ist auch egal. Um was es mir jetzt geht ist, das wenn ich mit tab durchgehe das 2. Control trotzdem den Focus bekommt obwohl es aus einem lable und einer deaktivierten TextBox besteht. Warum ist das so? Und wie kann ich das umgehen?

Danke für alle Antworten.

Computer, programmieren, C Sharp, Forms
discord.py AttributeError: 'ClientUser' object has no attribute 'avatar_url'?
Hi, 

ich bau momentan einen discord Bot mit python der ein Formular strten soll.

Code:

@bot.command()
async def testform(ctx):
    form = Form(ctx,'Title')
    form.add_question('Question 1','first')
    form.add_question('Question 2','second')
    form.add_question('Question 3','third')
    await form.start()

Error:

2023-09-09 08:58:09 ERROR    discord.ext.commands.bot Ignoring exception in command testform
Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/workspaces/moon/dir/.py/homeworkBOT/main.py", line 43, in testform
    await form.start()
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/forms/form.py", line 221, in start
    embed.set_author(name=f"{self.title}: {n+1}/{len(self._questions)}", icon_url=self._bot.user.avatar_url)
AttributeError: 'ClientUser' object has no attribute 'avatar_url'


The above exception was the direct cause of the following exception:


Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'avatar_url'

Ich verstehe nicht was mit 'avatar_url' gemeint ist da ich diese nicht in meinem Code benutze.

Ich hoffe jemand kann mir helfen.

Code, Python, Forms, Python 3, Discord, Discord Bot
Wie kann man im Qt Designer den Code einfach zu Python umwandeln?

Hallo.

Also ich brauche Hilfe. Ich würde gern Windows Forms über Python statt mit C# programmieren, weil Python kann bis unendlich viel rechnen als C# und daraus möchte ich einen super Taschenrechner programmieren.

Ich verwende den Qt Designer und versuche denn Code umzuwandeln. Ich habe im Internet geschaut und diesen Code eingegeben:

from PyQt5 import uic, QtWidgets
import sys
 
class Ui(QtWidgets.QDialog):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('Test.ui', self)
        self.show()
 
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = Ui()
    sys.exit(app.exec_())

Ja und wenn ich das dann ausführe, spuckt er diese Fehlermeldung aus:

Traceback (most recent call last):
  File "C:/Users/PrinzPersia/Documents/Test.py", line 12, in <module>
    window = Ui()
  File "C:/Users/PrinzPersia/Documents/Test.py", line 7, in __init__
    uic.loadUi('Test.ui', self)
  File "C:\Users\PrinzPersia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyQt5\uic__init__.py", line 226, in loadUi
    return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
  File "C:\Users\PrinzPersia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyQt5\uic\Loader\loader.py", line 72, in loadUi
    return self.parse(filename, resource_suffix, basedir)
  File "C:\Users\PrinzPersia\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyQt5\uic\uiparser.py", line 992, in parse
    document = parse(filename)
  File "C:\Users\PrinzPersia\AppData\Local\Programs\Python\Python35-32\lib\xml\etree\ElementTree.py", line 1183, in parse
    tree.parse(source, parser)
  File "C:\Users\PrinzPersia\AppData\Local\Programs\Python\Python35-32\lib\xml\etree\ElementTree.py", line 583, in parse
    source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Test.ui'

Wisst ihr, woran es liegt? Ich kenne mich im Qt Designer gar nicht gut aus und Videotutorials anschauen ist wegen der niedrigen Bildschirmauflösung sehr anstrengend.

PC, Computer, programmieren, Code, Python, Windows Forms, XML, Forms