小编Wes*_*dom的帖子

将文本居中放在WinForms应用程序中的按钮上

我有一个简单的Windows窗体应用程序tabControl.我有3个面板tabControl,每个面板有5个按钮.第一组按钮上的文本是硬编码的,但是当您从第一组中单击一个按钮时,下一组将填充,然后当您单击第二组中的一个按钮时,最后一组会再次发生相同的事情.在[Design]视图中,我手动设置TextAlign每个按钮的属性MiddleCenter.但是,当我运行应用程序时,中间按钮组上的文本永远不会居中.它始终是TopLeft对齐的.TextAlign每次我以编程方式设置按钮文本时,我都尝试更改字体大小甚至显式设置属性,如下所示:

private void setButtons(List<string> labels, Button[] buttons)
    {
        for (int i = 0; i < buttons.Count(); i++)
        {
            if (i < labels.Count)
            {
                buttons[i].Text = labels.ElementAt(i);
                buttons[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                buttons[i].Enabled = true;
            }
            else
            {
                buttons[i].Text = "";
                buttons[i].Enabled = false;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

此图像显示结果: 对齐问题

有没有人对我遗失的东西有任何想法?

c# winforms

5
推荐指数
1
解决办法
4628
查看次数

Django 自定义表单 ImportError 即使文件位于同一目录中

我正在学习Effective Django 的教程系列。我当前在尝试创建要在应用程序中使用的自定义表单时遇到问题。我按照本教程这一部分中的说明创建了 forms.py 文件,并对 view.py 文件进行了更改。我的目录结构如下所示:

\n\n
(project root)\n|\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 address.db\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 addressbook\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __pycache__\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 settings.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 static\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 urls.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wsgi.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 contacts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 admin.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 forms.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 models.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 templates\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tests.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 views.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 manage.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 requirements.txt\n
Run Code Online (Sandbox Code Playgroud)\n\n

问题是,当我尝试加载该网站时,出现以下错误:

\n\n
Traceback (most recent call last):\n  File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/handlers/base.py", line 101, in get_response\n    resolver_match = resolver.resolve(request.path_info)\n  File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/urlresolvers.py", line 318, in resolve\n    for pattern in self.url_patterns:\n  File "/Users/wtodom/.virtualenvs/tutorial/lib/python3.3/site-packages/django/core/urlresolvers.py", line 346, in url_patterns\n    patterns …
Run Code Online (Sandbox Code Playgroud)

python django django-forms python-3.x django-1.6

3
推荐指数
1
解决办法
2万
查看次数

Django教程(使用Heroku指南),"请提供ENGINE值"(是的,我已阅读其他主题)

我已经阅读了很多类似的问题,而且我花了很多时间尝试自己解决这个问题,但我仍然陷入困境.这是我的情况:

我正在浏览Heroku上的Django指南(https://devcenter.heroku.com/articles/django).我最初是在Windows中启动的,但在遇到各种各样的问题后,我认为切换到Linux会容易得多.我擦了我的硬盘驱动器并将Ubuntu 12.10和Win 7并排安装到双启动.一切都已经安装了pip(再次,遵循Heroku指南).我正在使用PostgreSQL,因为它(据说)与Heroku很好地集成.在我进入我尝试过的之前,这是错误(它来自教程的末尾):

(venv)wtodom@wubuntu:~/hellodjango$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
    raise ImproperlyConfigured("settings.DATABASES is …
Run Code Online (Sandbox Code Playgroud)

python django web-applications heroku

1
推荐指数
1
解决办法
1081
查看次数